package com.ss.android.video.b;

import android.app.Activity;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.Toast;

import com.bytedance.article.common.c.JSONObjectWrapper;
import com.bytedance.article.common.c.VideoLogManager;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.NetworkType;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.bytedance.ttnet.a.NetChannelSelect;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.app.BizApplication;
import com.ss.android.article.base.feature.app.schema.AdsAppActivity;
import com.ss.android.article.base.feature.detail2.DetailIntentCreator;
import com.ss.android.article.base.feature.detail2.DetailPageListener;
import com.ss.android.article.base.feature.e.VideoAutoPlayHelperDetail;
import com.ss.android.article.base.feature.feed.FeedTab;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.CellRef;
import com.ss.android.article.base.feature.video.IMediaCallback;
import com.ss.android.article.base.feature.video.IMediaLayout;
import com.ss.android.article.base.feature.video.IVideoController;
import com.ss.android.article.base.feature.video.IVideoFullscreen;
import com.ss.android.article.base.feature.video.MediaHelper;
import com.ss.android.article.base.feature.video.RelatedVideoItem;
import com.ss.android.article.base.feature.video.ThirdVideoPartnerData;
import com.ss.android.article.base.feature.video.VideoClarityHelper;
import com.ss.android.article.base.feature.video.VideoPref;
import com.ss.android.article.base.feature.video.cache.VideoCacheController;
import com.ss.android.article.base.feature.video.cache.VideoCacheManager;
import com.ss.android.article.base.utils.ArticleHelper;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.app.AbsApplication;
import com.ss.android.common.app.IComponent;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.callback.CallbackCenter;
import com.ss.android.common.callback.SSCallback;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.BaseApplication;
import com.ss.android.newmedia.a.AdsAppBaseActivity;
import com.ss.android.newmedia.util.AppUtil;
import com.ss.android.video.MediaViewLayout;
import com.ss.android.video.VideoEventReporter;
import com.ss.android.video.VideoStatistics;
import com.ss.android.video.a.VideoDiagnosis;
import com.ss.ttvideoengine.FetchVideoInfoListener;
import com.ss.ttvideoengine.Resolution;
import com.ss.ttvideoengine.TTVideoEngine;
import com.ss.ttvideoengine.VideoListener;
import com.ss.ttvideoengine.b.VideoDataContainer;
import com.ss.ttvideoengine.b.VideoInfo;
import com.ss.ttvideoengine.b.VideoItem;
import com.ss.ttvideoengine.d.TTVideoEngineLog;
import com.ss.ttvideoengine.d.TTVideoError;
import com.ss.ttvideoengine.dd;
import com.ss.ttvideoengine.log.VideoEventManager;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;

import okhttp3.SSAppCompatViewInflater;

public class TTVideoController implements Callback, IMediaCallback, IVideoController, dd, VideoListener, FetchVideoInfoListener {
    public static final int LOAD_STATE_BUFFER_START = 2;
    public static final int LOAD_STATE_BUFFER_END = 1;

    final class c$a implements OnAudioFocusChangeListener {
        private c$a() {

        }

        public final void onAudioFocusChange(int arg1) {
        }
    }

    final class b implements SSCallback {
        private WeakReference a;

        b(TTVideoController arg2) {

            this.a = new WeakReference(arg2);
        }

        public final Object onCallback(Object[] args) {
            if (args != null && args.length > 0 && ((args[0] instanceof Boolean))) {
                boolean v1 = ((Boolean) args[0]).booleanValue();
                Object v0 = this.a.get();
                if (v0 != null && ((TTVideoController) v0).mMediaViewLayout != null && (((TTVideoController) v0).isVideoVisible())) {
                    if (v1) {
                        ((TTVideoController) v0).mMediaViewLayout.disableAutoRotate();
                    } else if (!((TTVideoController) v0).e && (b(((TTVideoController) v0)))) {
                        ((TTVideoController) v0).mMediaViewLayout.enableAutoRotate();
                    }
                }
            }

            return null;
        }
    }

    final class ReshowEndCoverCallback implements SSCallback {
        private WeakReference a;

        ReshowEndCoverCallback(TTVideoController arg2) {

            this.a = new WeakReference(arg2);
        }

        public final Object onCallback(Object[] args) {
            Object v1 = null;
            Object v0 = this.a != null ? this.a.get() : v1;
            if (v0 != null && ((TTVideoController) v0).getMediaViewLayout() != null) {
                ((TTVideoController) v0).getMediaViewLayout().reshowEndCover();
            }

            return v1;
        }
    }

    final static class StopAutoPlayAnimationCallback implements SSCallback {
        private WeakReference<TTVideoController> mTTVideoControllerRef;

        StopAutoPlayAnimationCallback(TTVideoController ttVideoController) {
            this.mTTVideoControllerRef = new WeakReference(ttVideoController);
        }

        @Override
        public final Object onCallback(Object[] args) {
            TTVideoController ttVideoController = this.mTTVideoControllerRef != null ? this.mTTVideoControllerRef.get() : null;
            if (ttVideoController != null) {
                ttVideoController.stopAutoPlayAnimation();
            }
            return null;
        }
    }

    private long mTotalPlayTime = 0;
    private long mLastBufferEndTime = 0;
    private WeakReference C;
    private WeakReference D;
    private boolean E = false;
    private long F = 0;
    private Object G;
    private VideoEventReporter mVideoEventReporter;
    private VideoStatistics mVideoStatistics;
    private WeakReference<ICloseListener> mCloseListenerRef;
    private WeakReference<IVideoFullscreen> mVideoFullscreenRef;
    private WeakReference<IShareListener> mShareListenerRef;
    private long M = 0;
    private boolean N = false;
    private long O;
    private ArrayList<Runnable> mPendingTaskOnSurfaceCreatedList;
    private boolean isPendingTaskRunning;
    private int mVideoWidth = 0;
    private int mVideoHeight = 0;
    private boolean isPauseFromList = false;
    private boolean U = false;
    private String V;
    private boolean isActivityOnDestroy = false;
    private boolean X = false;
    private boolean Y = false;
    private long Z = 0;
    WeakReference<Context> mRefContext;
    private JSONObject logPb;
    private long searchResultId = 0;
    private String query;
    private String source;
    private VideoDataContainer mVideoDataContainer;
    private final Runnable aF = new Runnable() {

        public final void run() {
            if (mTTVideoEngine != null) {
                long v2 = (long) mTTVideoEngine.d();
                long v4 = (long) mTTVideoEngine.mDuration;
                TTVideoController.this.mCurrent = v2;
                TTVideoController.this.mDuration = v4;
                int progress = (int) ((double) v2 / (double) v4 * 100);
                if (mMediaViewLayout != null) {
                    mMediaViewLayout.setTimeDesc(v2, v4);
                    mMediaViewLayout.setSeekProgress(progress);
                }
            }
            if (mWeakHandler != null) {
                mWeakHandler.postDelayed(this, 600);
            }
        }
    };
    private long aG = 0;
    private long aH;
    private ReshowEndCoverCallback mReshowEndCoverCallback;
    private StopAutoPlayAnimationCallback mStopAutoPlayAnimationCallback;
    private TTVideoEngine mTTVideoEngine;
    private VideoInfo mVideoInfo;
    private String mDefinition = "";
    private int aN;
    private c$a mOnAudioFocusChangeListener;
    private b aP;
    private long aa = 0;
    private boolean isReceiverRegistered = false;
    private boolean isDirectPlay = false;
    private boolean ad = true;
    private long ae = 0;
    private String af;
    private boolean ag = false;
    private ThirdVideoPartnerData mThirdVideoPartnerData;
    private WeakReference<IThirdPartnerListner> mThirdPartnerListnerRef;
    private WeakReference<ISplashAdListener> mSplashAdListenerRef;
    private static TTVideoController sInstance;
    private boolean al = false;
    private int am = 3;
    private int an = -1;
    private int ao = -1;
    private boolean ap = false;
    private boolean aq = false;
    private boolean ar = false;
    private int as = 0;
    private int at = 5000;
    private int au = 10;
    private String av = "";
    private VideoAutoPlayHelperDetail mVideoAutoPlayHelperDetail = VideoAutoPlayHelperDetail.getInstance();
    private WeakReference<IPlayCompleteListener> mPlayCompleteListenerRef;
    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {

        public final void onReceive(Context context, Intent intent) {
            long v6 = 0;
            String action = intent.getAction();
            if (mTTVideoEngine != null && mTTVideoEngine.prevPlaybackState == 1) {
                if ("android.intent.action.SCREEN_OFF".equals(action)) {
                    pauseVideo();
                } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {
                    NetworkType networkType = NetworkUtils.getNetworkType(context);
                    if ((mMediaViewLayout == null || !mMediaViewLayout.isNoWifiDialogShowing()) && (!AppData.getInstance().userAllowUseMobileNet && networkType != NetworkType.WIFI && networkType != NetworkType.NONE)) {
                        pauseVideo();
                        mMediaViewLayout.showNoWifiNoticeDialog(mRefContext.get());
                        AbsApplication application = BaseApplication.getApplication();
                        long v4 = mArticle != null ? mArticle.groupId : v6;
                        MobClickCombiner.onEvent(application, "video", "net_alert_show", v4, v6);
                        if (TTVideoController.this.i) {
                            v4 = mArticle != null ? mArticle.groupId : v6;
                            MobClickCombiner.onEvent(application, "live", "network_hint", v4, v6);
                        }
                    }

                    if (!AppData.getInstance().getAbSettings().isVideoUseIpUrl()) {
                        return;
                    }

                    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
                    if (networkInfo == null) {
                        return;
                    }

                    if (!networkInfo.isConnected()) {
                        return;
                    }
                    NetChannelSelect.d(context);
                }
            }
        }
    };
    private Runnable az = new Runnable() {

        public final void run() {
            FrameLayout.LayoutParams layoutParams = mMediaViewLayout.getLayoutParams();
            if (layoutParams != null) {
                layoutParams.topMargin = TTVideoController.this.g[1] - TTVideoController.this.h[1];
                layoutParams.leftMargin = TTVideoController.this.g[0];
                layoutParams.gravity = 51;
                mMediaViewLayout.setLayoutParams(layoutParams);
                mMediaContainer.requestLayout();
            }
        }
    };
    Article mArticle;
    WeakHandler mWeakHandler = new WeakHandler(this);
    IMediaLayout mMediaViewLayout;
    boolean e;
    ViewGroup mMediaContainer;
    int[] g = new int[2];
    int[] h = new int[2];
    boolean i = false;
    int j;
    long mCurrent;
    long mDuration;
    private boolean isFromFeed;
    private WeakReference<DetailPageListener> mDetailPageListenerRef;
    private long o;
    private String mLogExtra;
    private JSONObject q;
    private String mCategoryName;
    private String mVideoId;
    private boolean isVideoFullscreen = false;
    private boolean isError = false;
    private boolean v = false;
    private boolean isPrepared = false;
    private boolean isJellyBeanMR1 = false;
    private String y;
    private long z;

    private TTVideoController() {
        this.l();
    }

    public TTVideoController(Context arg2, ViewGroup arg3, boolean arg4) {
        this(arg2, arg3, arg4, null);
    }

    public TTVideoController(Context context, ViewGroup arg8, boolean arg9, EnumSet arg10) {
        this.mRefContext = new WeakReference(context);
        this.l();
        this.mMediaContainer = arg8;
        this.isFromFeed = arg9;
        this.a(context, arg9, arg10);
    }

    private void a(Context context, boolean arg7, EnumSet arg8) {
        this.mMediaViewLayout = new MediaViewLayout(context,
                SSAppCompatViewInflater.from(context.getApplicationContext()).inflate(com.ss.android.article.browser.R.layout.media_play_layout,
                        null, false), arg7, arg8);
        AppData.getInstance();
        this.mMediaViewLayout.setTheme(AppData.isNightMode());
        this.mMediaViewLayout.setCallback(this);
    }

    public static TTVideoController getInstance() {
        if (sInstance == null) {
            synchronized (TTVideoController.class) {
                if (sInstance == null) {
                    sInstance = new TTVideoController();
                }
            }
        }
        return sInstance;
    }

    private void seekTo(long position) {
        VideoLogManager.appendLog("seekTo" + position);
        if (this.mTTVideoEngine != null) {
            int time = (int) position;
            TTVideoEngineLog.log("TTVideoEngine", String.format("seek to time:%d", time));
            mTTVideoEngine.i = this;
            mTTVideoEngine.seekTo(time, false);
            this.d();
        }
    }

    private void a(long arg8, long arg10) {
        long v4 = 1000;
        if (!this.isFromFeed || !this.isDirectPlay()) {
            if (this.an <= 0) {
                this.an = (((int) arg10)) / 1000;
            }

            this.mDuration = arg10;
            this.mCurrent = arg8;
            this.mMediaViewLayout.setTimeDesc(arg8, arg10);
            this.mMediaViewLayout.setSeekProgress(MediaHelper.timeToPercent(arg8, arg10));
            if (TextUtils.equals(this.mVideoId, VideoPref.getLastVideoId())) {
                VideoPref.setLastVideoPos(arg8);
            }

            if (!this.isPatchVideo()) {
                this.aH = this.mDuration;
            }

            if (!this.isPatchVideo()) {
                return;
            }

            int v0 = (((int) (arg8 - this.aG))) / 1000;
            if (v0 <= 0) {
                return;
            }

            this.aG = arg8;
            this.an -= v0;
            this.ao -= v0;
            if (this.ao > 0) {
                this.mMediaViewLayout.updateAdLeftTime(((int) ((arg10 - arg8) / v4)), this.ao);
                return;
            }

            this.mMediaViewLayout.updateAdLeftTime(((int) ((arg10 - arg8) / v4)), -1);
        }
    }

    private void a(Context context, String arg14, JSONObject arg15) {
        String categoryName;
        long v10 = 0;
        String v3 = this.getCategoryLabel("click");
        if (AppData.getInstance().getAbSettings().isAppLogOld()) {
            try {
                if (this.mArticle == null) {
                } else {
                    arg15.put("item_id", this.mArticle.itemId);
                    arg15.put("aggr_type", this.mArticle.aggrType);
                    MobClickCombiner.onEvent(context, arg14, v3, this.mArticle.groupId, this.o, arg15);
                }
            } catch (JSONException v0) {
            }
        }

        if (AppData.getInstance().getAbSettings().isAppLogNew()) {
            JSONObjectWrapper v2 = new JSONObjectWrapper();
            String v4 = "group_id";
            long v0_1 = this.mArticle != null ? this.mArticle.groupId : v10;
            JSONObjectWrapper v4_1 = v2.put(v4, Long.valueOf(v0_1));
            String v5 = "item_id";
            v0_1 = this.mArticle != null ? this.mArticle.itemId : v10;
            JSONObjectWrapper v1 = v4_1.put(v5, Long.valueOf(v0_1));
            v4 = "aggr_type";
            int v0_2 = this.mArticle != null ? this.mArticle.aggrType : 0;
            v1.put(v4, Integer.valueOf(v0_2)).put("ad_id", Long.valueOf(this.o)).put("log_pb", this.logPb);
            if (this.mArticle != null) {
                v2.put("author_id", Long.valueOf(this.mArticle.getUserId()));
            }
            if (v3.equals("click_" + this.mCategoryName)) {
                v3 = "click_category";
                categoryName = this.mCategoryName;
            } else if (v3.equals("click_headline")) {
                categoryName = this.mCategoryName;
            } else {
                categoryName = v3.replaceFirst("click_", "");
            }
            if (this.searchResultId != v10) {
                v2.put("search_result_id", Long.valueOf(this.searchResultId))
                        .put("query", this.query)
                        .put("source", this.source);
            }

            v2.put("enter_from", v3).put("category_name", categoryName);
            if (AppData.getInstance().getAbSettings().isApplogStaging()) {
                v2.put("_staging_flag", Integer.valueOf(1));
            }
            v2.put(arg15);
            android.support.design.a.onEvent(arg14, v2.jo);
        }
    }

    private void schedulePendingTask(Runnable runnable) {
        if (!this.mMediaViewLayout.isSurfaceViewValid() || !this.X) {
            if (this.mPendingTaskOnSurfaceCreatedList == null) {
                this.mPendingTaskOnSurfaceCreatedList = new ArrayList();
            }
            this.mPendingTaskOnSurfaceCreatedList.add(runnable);
        } else {
            runnable.run();
        }
    }

    private void a(String arg10) {
        boolean v0_1;
        int v8 = 8;
        if (this.isContextAlive()) {
            this.U = false;
            this.y = arg10;
            if ((this.isFromFeed) && (this.isDirectPlay())) {
                this.mMediaViewLayout.setDirectPlay(true);
                this.mMediaViewLayout.dismissToolBar(false, false);
                mMediaViewLayout.trySetTitleVisiable(false);
            } else if (this.al) {
                mMediaViewLayout.dismissToolBar(false, !this.isPatchVideo());
                mMediaViewLayout.trySetTitleVisiable(false);
            } else {
                if (this.i) {
                    this.mMediaViewLayout.dismissToolBar(false, false);
                } else {
                    this.mMediaViewLayout.setDirectPlay(false);
                    this.mMediaViewLayout.showToolBar(false);
                    if (this.isFromFeed) {
                        if (this.isFullScreen()) {
                            v0_1 = false;
                        } else {
                            v0_1 = true;
                        }
                    } else {
                        v0_1 = false;
                    }
                    mMediaViewLayout.trySetTitleVisiable(v0_1);
                }
            }
            if (this.o <= 0 || (this.isFromFeed) || (android.support.design.a.isTextEmpty(this.af)) || (this.isPatchVideo())) {
                this.mMediaViewLayout.setAdGoLanding(false);
            } else {
                this.mMediaViewLayout.setAdGoLanding(true);
            }

            this.mMediaViewLayout.dismissCover();
            v0_1 = !this.al;
            mMediaViewLayout.setPlayerSurfaceViewSize(v0_1);
            Logger.d("TTVideoController", "Get Video Source: " + this.y);
            this.mMediaViewLayout.setPlayIcon(false, false);
            if ((AppData.getInstance().hasVideoKeepPos()) && (TextUtils.equals(this.mVideoId, VideoPref.getLastVideoId()))) {
                this.O = VideoPref.getLastVideoPos();
            }

            if (this.X) {
                this.Y = true;
                this.mMediaViewLayout.setSurfaceViewVisible(v8);
                this.mMediaViewLayout.setSurfaceViewVisible(0);
                this.a(true);
                return;
            }

            this.Y = false;
            this.X = false;
            this.mMediaViewLayout.setSurfaceViewVisible(v8);
            this.mMediaViewLayout.setSurfaceViewVisible(0);
            this.schedulePendingTask(new Runnable() {
                public final void run() {
                    TTVideoController.this.a(true);
                }
            });
        }
    }

    final void a(boolean arg13) {
        long v8 = -1;
        int v6 = 3;
        this.mMediaViewLayout.setPlayIcon(false, this.i);
        boolean v0 = !this.isDirectPlay || !this.isFromFeed ? true : false;
        this.ad = v0;
        if (this.isPatchVideo()) {
            this.mMediaViewLayout.updateAdPatchVideoPanel(true);
        }

        long v4 = this.O;
        DetailPageListener detailPageListener = this.mDetailPageListenerRef == null ? null : this.mDetailPageListenerRef.get();
        if (!this.isFromFeed && detailPageListener != null) {
            detailPageListener.onVideoCompletion(false);
        }

        if (this.am != v6 || (this.i)) {
            this.O = v8;
        } else if (!TextUtils.equals(this.mVideoId, VideoPref.getLastVideoId())) {
            VideoPref.setLastVideoId(this.mVideoId);
            VideoPref.setLastVideoPos(v8);
        }

        if (this.isDirectPlay() && this.isFromFeed) {
            this.mMediaViewLayout.disableAutoRotate();
        } else if (this.ap) {
            this.mMediaViewLayout.disableAutoRotate();
        } else {
            this.mMediaViewLayout.enableAutoRotate();
        }

        if (this.mMediaViewLayout != null) {
            this.mMediaViewLayout.setKeepScreenOn(true);
        }

        this.mMediaViewLayout.setVisibility(View.VISIBLE);
        if (this.mTTVideoEngine != null) {
            if (v4 > 0L && (arg13)) {
                this.mTTVideoEngine.u = ((int) v4);
            }

            TTVideoEngine v3 = this.mTTVideoEngine;
            v0 = !this.ad ? true : false;
            v3.isMute = v0;
            v3.setIsMute(v0);
            if (this.ad) {
                try {
                    if (this.mOnAudioFocusChangeListener != null) {
                    } else {
                        this.mOnAudioFocusChangeListener = new c$a();
                        ((AudioManager) AbsApplication.getApplication()
                                .getSystemService(Context.AUDIO_SERVICE))
                                .requestAudioFocus(this.mOnAudioFocusChangeListener, 3, 1);
                    }
                } catch (Throwable v0_2) {
                }
            } else {
                this.abandonAudioFocus();
            }

            TTVideoEngine v0_3 = this.mTTVideoEngine;
            TTVideoEngineLog.log("TTVideoEngine", "play");
            v0_3.B = true;
            TTVideoEngineLog.log("TTVideoEngine", String.format("_play, mState:%d", Integer.valueOf(v0_3.mState)));
            switch (v0_3.mState) {
                case 1: {
                    if (v0_3.mVideoDataContainer == null) {
                        break;
                    }

                    v0_3.a(v0_3.mVideoDataContainer);
                    break;
                }
                case 3: {
                    if (v0_3.prevPlaybackState != 0 && v0_3.prevPlaybackState != v6) {
                        v0_3.resumeVideo();
                        break;
                    }

                    v0_3.x = 0;
                    v0_3.n.a(v0_3.d);
                    v0_3.startPlay(v0_3.mCurrentHost, v0_3.mCurrentIp);
                    break;
                }
                case 0:
                case 4: {
                    v0_3.n.a(v0_3.d);
                    v0_3.e();
                    break;
                }
            }
            if (this.mMediaViewLayout == null || !this.mMediaViewLayout.isAutoRotateEnabled()) {
                if (this.aP != null) {
                    CallbackCenter.addCallback(BaseAppData.callbackTypePopUiShowStateChanged, this.aP);
                }
            } else {
                if (this.aP == null) {
                    this.aP = new b(this);
                }
                CallbackCenter.addCallback(BaseAppData.callbackTypePopUiShowStateChanged, this.aP);
            }
            this.d();
        }

        this.e = false;
        if (!arg13 && this.mLastBufferEndTime <= 0L) {
            this.mLastBufferEndTime = System.currentTimeMillis();
        }
    }

    private void tryPlay(String arg11, String arg12, int arg13) {
        VideoLogManager.appendLog("tryPlay");
        this.mVideoId = arg12;
        this.aN = arg13;
        if (this.isDirectPlay()) {
            this.mMediaViewLayout.setDirectPlay(true);
            this.mMediaViewLayout.dismissToolBar(false, false);
            this.mMediaViewLayout.trySetTitleVisiable(false);
        } else if (this.al) {
            mMediaViewLayout.dismissToolBar(false, !this.isPatchVideo());
            this.mMediaViewLayout.trySetTitleVisiable(false);
        } else if (this.i) {
            this.mMediaViewLayout.dismissToolBar(false, false);
        }
        if (this.i) {
            MobClickCombiner.onEvent(BaseApplication.getApplication(),
                    "live",
                    "loading",
                    this.mArticle != null ? this.mArticle.groupId : 0L,
                    0L);
        }

        if (this.mArticle != null && this.mArticle.mLoadingCoverImageInfo != null) {
            this.mMediaViewLayout.showLoadingCover(this.mArticle.mLoadingCoverImageInfo);
        }

        this.mMediaViewLayout.showLoading();
        VideoCacheController.getInstance().parseUrlFromArticleIfNeed(this.mArticle);
        VideoDataContainer v0_1 = VideoCacheController.getInstance().getDataContainer(arg12);
        if (v0_1 != null) {
            this.mVideoDataContainer = v0_1;
            if ((this.aq) && (VideoCacheController.getInstance().hasFailed(arg12))) {
                this.aq = false;
            }
        }

        VideoEventManager.instance.setListener(VideoEventExecutor.getInstance());
        boolean v1_2 = AppData.getInstance().isTTPlayerEnable();
        boolean v2_1 = AppData.getInstance().h();
        int v0_2 = 2;
        if (v1_2) {
            v0_2 = v2_1 ? 1 : 0;
        }

        TTVideoEngineLog.a();
        this.mTTVideoEngine = new TTVideoEngine(BizApplication.getApplication(), v0_2);
        this.mTTVideoEngine.e = new MediaPlayerHttpRequest();
        this.mTTVideoEngine.mVideoListener = ((VideoListener) this);
        this.mTTVideoEngine.mFetchVideoInfoListener = ((FetchVideoInfoListener) this);
        this.mTTVideoEngine.f = new com.ss.ttvideoengine.aa(this.mVideoId, this.mArticle, this.mCategoryName, this.o);
        TTVideoEngine v0_3 = this.mTTVideoEngine;
        String v1_3 = this.mVideoId;
        if (v1_3 != null && !v1_3.equals(v0_3.d)) {
            TTVideoEngineLog.log("TTVideoEngine", String.format("set video id:%s", v1_3));
            if (v0_3.d != null) {
                v0_3.stop();
            }

            v0_3.z = true;
            v0_3.mState = 0;
            v0_3.s = false;
            v0_3.t = 0;
        }

        v0_3.w = TTVideoEngine.v;
        v0_3.x = 0;
        v0_3.d = v1_3;
        com.ss.ttvideoengine.log.c v2_2 = v0_3.n;
        v2_2.b = v1_3;
        v2_2.c();
        v0_3.p.clear();
        if (!TextUtils.isEmpty(((CharSequence) arg11))) {
            try {
                this.a(URLDecoder.decode(arg11, "UTF-8"));
            } catch (UnsupportedEncodingException v0_4) {
            }

            return;
        }

        try {
            String v0_6 = !android.support.design.a.isTextEmpty(arg11) ? URLDecoder.decode(arg11, "UTF-8") : "";
            this.a(v0_6);
        } catch (Exception v0_5) {
        }
    }

    private void a(String arg2, JSONObject arg3) {
        this.a(BaseApplication.getApplication(), arg2, arg3);
    }

    private void a(JSONObject arg7) {
        String v0_1;
        if (this.mVideoDataContainer != null && this.mVideoDataContainer.mVideoInfo != null) {
            try {
                arg7.put("clarity_num", this.mMediaViewLayout.getClarityCount());
                if (VideoClarityHelper.isAutoMode()) {
                    arg7.put("clarity_choose", "AUTO");
                } else {
                    switch (VideoClarityHelper.getDefaultVideoClarity()) {
                        case 0: {
                            v0_1 = "720p";
                            break;
                        }
                        case 1: {
                            v0_1 = "480p";
                            break;
                        }
                        default: {
                            v0_1 = "360p";
                            break;
                        }
                    }

                    arg7.put("clarity_choose", v0_1);
                }

                arg7.put("clarity_actual", this.mDefinition);
                arg7.put("clarity_change_time", MediaHelper.timeToPercent(0, this.mDuration));
            } catch (Throwable v0) {
                v0.printStackTrace();
            }
        }
    }

    private static boolean shouldPreloadVideo(Article article) {
        return article.shouldPreloadVideo() || VideoCacheController.isDebugOpen();
    }

    public final void onPlaybackStateChanged(int state) {
        switch (state) {
            case 1: {
                this.mWeakHandler.sendEmptyMessage(1);
                break;
            }
        }
    }

    public final void onVideoSizeChanged(int width, int height) {
        Logger.d("TTVideoController", "onVideoSizeChanged called width:" + width + " height:" + height);
    }

    public final void onError(TTVideoError ttVideoError) {
        this.isError = true;
        this.abandonAudioFocus();
        this.mMediaViewLayout.dismissLoading();
        this.mMediaViewLayout.showRetry();
        this.mMediaViewLayout.setKeepScreenOn(false);
        this.mTotalPlayTime = 0;
        VideoLogManager.appendLog("onError" + (ttVideoError != null ? ttVideoError.code : 0));
    }

    public final boolean onFetchedVideoInfo(VideoDataContainer videoDataContainer) {
        VideoLogManager.appendLog("onFetchedVideoInfo");
        if (videoDataContainer != null && videoDataContainer != null) {
            this.mVideoDataContainer = videoDataContainer;
            this.mVideoInfo = videoDataContainer.mVideoInfo;
            VideoItem videoItem = VideoClarityHelper.getVideoInfoWithClarity(VideoClarityHelper.getSupportVideoInfos(mVideoInfo));
            if (videoItem == null) {
                videoItem = VideoClarityHelper.getVideoInfo(mVideoInfo, 2);
            }
            if (videoItem == null) {
                return false;
            }
            this.mMediaViewLayout.restoreClaritySelectByCache(
                    VideoClarityHelper.getDefinitionStr(videoItem.definition),
                    VideoClarityHelper.getSupportVideoInfos(this.mVideoInfo));
            this.mMediaViewLayout.setSelectClarityItem(videoItem, null);
            this.mDefinition = videoItem.definition;
            this.mMediaViewLayout.setVideoSize(videoItem.videoWidth, videoItem.videoHeight);
            this.mMediaViewLayout.setPlayerSurfaceViewSize(true);
            this.mVideoWidth = videoItem.videoWidth;
            this.mVideoHeight = videoItem.videoHeight;
            if (this.mTTVideoEngine == null) {
                return false;
            }
            String definitionStr = VideoClarityHelper.getDefinitionStr(videoItem.definition);
            Resolution resolution;
            if (TextUtils.equals(definitionStr, "高清")) {
                resolution = Resolution.SuperHigh;
            } else if (TextUtils.equals(definitionStr, "流畅")) {
                resolution = Resolution.High;
            } else {
                TextUtils.equals(definitionStr, "极速");
                resolution = Resolution.Standard;
            }
            mTTVideoEngine.configResolution(resolution);
        }
        return false;
    }

    public static void releaseInstance() {
        sInstance = null;
    }

    private void setContainerSize(int width, int height) {
        if (this.mMediaViewLayout != null) {
            this.mMediaViewLayout.setContainerSize(width, height);
        }
    }

    private void releaseMedia(boolean arg21) {
        VideoLogManager.appendLog("releaseMedia" + arg21);
        VideoCacheManager.getInstance().cancelPreDownload();
        if (this.mMediaViewLayout != null) {
            this.mMediaViewLayout.setKeepScreenOn(false);
            this.mMediaViewLayout.disableAutoRotate();
        }

        if ((this.isContextAlive()) && ((arg21) || !this.isFromFeed || !this.E)) {
            if (this.mTTVideoEngine != null) {
                if (!this.e) {
                    long v2 = this.getCurrentPlayPosition();
                    if (v2 > 0 && !android.support.design.a.isTextEmpty(this.mVideoId)) {
                        VideoPref.setLastVideoPos(v2);
                    }
                }

                this.mTTVideoEngine.c();
            }

            Object v2_2;
            if (!this.isFromFeed
                    && !this.i
                    && this.mVideoAutoPlayHelperDetail != null
                    && this.mVideoAutoPlayHelperDetail.a(this.isVideoFullscreen, this.isAd(), this.mThirdVideoPartnerData)
                    && (this.isVideoFullscreen)) {
                VideoAutoPlayHelperDetail.dismissVolumeOrTouchView(this.mMediaViewLayout);
            } else if (this.mMediaViewLayout != null) {
                this.mMediaViewLayout.dismissNoWifiNoticeDialog();
                if (this.isVideoFullscreen) {
                    this.isVideoFullscreen = !this.isVideoFullscreen;
                    this.mMediaViewLayout.exitFullScreen(this.mMediaContainer);
                    this.requestOrienation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    IVideoFullscreen videoFullscreen = this.mVideoFullscreenRef != null ? this.mVideoFullscreenRef.get() : null;
                    if (videoFullscreen != null) {
                        videoFullscreen.onFullscreenChanged(this.isVideoFullscreen);
                    }
                }
                this.mMediaViewLayout.releaseMediaPlayer();
            }

            this.e();
            if (this.C != null) {
                this.C.clear();
            }

            if (this.D != null) {
                v2_2 = this.D.get();
                if (v2_2 != null && ((v2_2 instanceof RelativeLayout))) {
                    ((RelativeLayout) v2_2).removeAllViews();
                    ((View) v2_2).setVisibility(View.GONE);
                }
                this.D.clear();
            }
            this.G = null;
            if (this.mVideoStatistics != null && !android.support.design.a.isTextEmpty(this.mVideoId)) {
                this.mVideoStatistics.a(this.e);
            }

            if (!this.ap) {
                String v2_3;
                if (!this.e && !android.support.design.a.isTextEmpty(this.mVideoId)) {
                    if (this.isFromFeed) {
                        if (!this.isFromFeed) {
                        } else if (!this.isDirectPlay()) {
                            VideoEventReporter v3 = this.mVideoEventReporter;
                            v2_3 = this.isFromFeed ? "feed_break" : "detail_break";
                            v3.onEvent(v2_3);
                        }
                    } else {
                        VideoEventReporter v3 = this.mVideoEventReporter;
                        v2_3 = this.isFromFeed ? "feed_break" : "detail_break";
                        v3.onEvent(v2_3);
                    }
                }

                JSONObject v10 = new JSONObject();
                try {
                    if (this.mLastBufferEndTime > 0) {
                        this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                        this.mLastBufferEndTime = 0;
                    }

                    v10.put("duration", this.mTotalPlayTime - this.aa);
                    v10.put("percent", MediaHelper.timeToPercent(this.mCurrent, this.mDuration));
                    v10.put("small_play_time", this.aa);
                    v10.put("log_extra", this.mLogExtra);
                    if (this.mArticle == null) {
                    } else if (this.mArticle.videoSubjectId <= 0) {
                    } else {
                        v10.put("video_subject_id", this.mArticle.videoSubjectId);
                    }
                } catch (Exception e) {
                }

                if (!this.e && this.o > 0 && !android.support.design.a.isTextEmpty(this.mVideoId)) {
                    if (this.isFromFeed) {
                        if (!this.isFromFeed) {
                        } else if (!this.isDirectPlay()) {
                            if (this.isPatchVideo()) {
                                Application application = BaseApplication.getApplication();
                                MobAdClickCombiner.onAdEvent(
                                        application,
                                        "embeded_ad",
                                        this.isFromFeed ? "patch_feed_break" : "patch_detail_break",
                                        this.o,
                                        0,
                                        v10,
                                        0);
                            } else {
                                Application application = BaseApplication.getApplication();
                                MobAdClickCombiner.onAdEvent(application,
                                        "embeded_ad",
                                        this.isFromFeed ? "feed_break" : "detail_break",
                                        this.o,
                                        0,
                                        v10,
                                        0);
                            }
                        }
                    } else {
                        if (this.isPatchVideo()) {
                            Application application = BaseApplication.getApplication();
                            MobAdClickCombiner.onAdEvent(application,
                                    "embeded_ad",
                                    this.isFromFeed ? "patch_feed_break" : "patch_detail_break",
                                    this.o,
                                    0,
                                    v10,
                                    0);
                        } else {
                            Application application = BaseApplication.getApplication();
                            MobAdClickCombiner.onAdEvent(application,
                                    "embeded_ad",
                                    this.isFromFeed ? "feed_break" : "detail_break",
                                    this.o,
                                    0,
                                    v10,
                                    0);
                        }
                    }
                }
                if (this.e) {
                } else if (this.mArticle == null) {
                } else {
                    String v3_2;
                    try {
                        v3_2 = "position";
                        v2_3 = this.isFromFeed ? "list" : "detail";
                        v10.put(v3_2, v2_3);
                        v10.put("item_id", this.mArticle.itemId);
                        v10.put("aggr_type", this.mArticle.aggrType);
                        if (this.mArticle.videoSubjectId > 0) {
                            v10.put("video_subject_id", this.mArticle.videoSubjectId);
                        }
                        this.a(v10);
                    } catch (JSONException jsonException) {
                    }

                    Object v4_2;
                    VideoAutoPlayHelperDetail v3_3;
                    if ((this.isDirectPlay) && (this.isFromFeed)) {
                        JSONObject v18 = new JSONObject();
                        try {
                            v18.put("duration", this.mTotalPlayTime);
                            v18.put("percent", MediaHelper.timeToPercent(this.mCurrent, this.mDuration));
                            v18.put("log_extra", this.mLogExtra);
                            v3_2 = "position";
                            v2_3 = this.isFromFeed ? "list" : "detail";
                            v18.put(v3_2, v2_3);
                            v18.put("item_id", this.mArticle.itemId);
                            if (this.mArticle.videoSubjectId > 0) {
                                v18.put("video_subject_id", this.mArticle.videoSubjectId);
                            }
                            this.a(v18);
                        } catch (JSONException jsonException) {
                        }

                        if (this.o > 0) {
                            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "feed_auto_over", this.o, 0, v18, 2);
                        } else if (!this.o()) {
                            MobClickCombiner.onEvent(BaseApplication.getApplication(), "video_over", "feed_auto_over", this.mArticle.groupId, 0, v18);
                        } else if (!this.isFromFeed && this.mVideoAutoPlayHelperDetail != null) {
                            v3_3 = this.mVideoAutoPlayHelperDetail;
                            if (this.mRefContext == null) {
                                v4_2 = null;
                            } else {
                                v4_2 = this.mRefContext.get();
                            }

                            v3_3.onEvent(((Context) v4_2), this.getCategoryLabel("click"), this.mArticle.groupId, this.o, v10);
                        }

                        if (!this.ag) {
                        } else {
                            this.a("video_over", v10);
                        }
                    } else {
                        if (!this.o()) {
                            this.a("video_over", v10);
                        } else if (!this.isFromFeed && this.mVideoAutoPlayHelperDetail != null) {
                            v3_3 = this.mVideoAutoPlayHelperDetail;
                            if (this.mRefContext == null) {
                                v4_2 = null;
                            } else {
                                v4_2 = this.mRefContext.get();
                            }

                            v3_3.onEvent(((Context) v4_2), this.getCategoryLabel("click"), this.mArticle.groupId, this.o, v10);
                        }
                    }
                }
            }

            v2_2 = this.mCloseListenerRef != null ? this.mCloseListenerRef.get() : null;
            if (!this.isFromFeed && v2_2 != null && (this.v)) {
                this.v = false;
                ((ICloseListener) v2_2).onClose(true);
            }

            this.mTTVideoEngine = null;
            this.isDirectPlay = false;
            this.ag = false;
            this.af = null;
            this.mCategoryName = null;
            this.mTotalPlayTime = 0;
            this.mLastBufferEndTime = 0;
            this.mCurrent = 0;
            this.mDuration = 0;
            this.e = false;
            this.isPrepared = false;
            this.isError = false;
            this.z = 0;
            this.y = null;
            this.O = -1;
            this.mVideoHeight = 0;
            this.mVideoWidth = 0;
            this.mVideoId = null;
            this.v = false;
            this.aa = 0;
            this.am = -1;
            this.mArticle = null;
            this.mThirdPartnerListnerRef = null;
            this.mThirdVideoPartnerData = null;
            this.Y = false;
            this.al = false;
            this.aG = 0;
            this.an = 0;
            this.ao = 0;
            this.ap = false;
            this.i = false;
            this.aH = 0;
            this.as = 0;
            this.doUnregisterReceiver();
            this.s();
            this.abandonAudioFocus();
            if (this.mMediaViewLayout != null) {
                this.mMediaViewLayout.clearView();
            }

            this.aq = false;
        }
    }

    static boolean b(TTVideoController ttVideoController) {
        return !(ttVideoController.isDirectPlay() && ttVideoController.isFromFeed);
    }

    @Override
    public final void onLoadStateChanged(int loadState) {
        Logger.d("TTVideoController", "onLoadStateChanged loadState:" + loadState);
        switch (loadState) {
            case LOAD_STATE_BUFFER_END: {
                this.mLastBufferEndTime = System.currentTimeMillis();
                this.mMediaViewLayout.dismissLoading();
                this.mMediaViewLayout.sendDismissToolBarMsg();
                VideoLogManager.appendLog("onBufferEnd");
                break;
            }
            case LOAD_STATE_BUFFER_START: {
                if (this.mLastBufferEndTime > 0L) {
                    this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                    this.mLastBufferEndTime = 0L;
                }
                this.mMediaViewLayout.showLoading();
                VideoLogManager.appendLog("onBufferStart");
                break;
            }
        }
    }

    @Override
    public boolean backPress(Activity activity) {
        boolean v2 = false;
        VideoLogManager.appendLog("backPress");
        if (this.isVideoVisible()) {
            if (this.isVideoFullscreen) {
                this.isVideoFullscreen = !this.isVideoFullscreen;
                this.mMediaViewLayout.exitFullScreen(this.mMediaContainer);
                IMediaLayout v0_1 = this.mMediaViewLayout;
                if ((this.isFromFeed) && (this.e)) {
                    v2 = true;
                }
                v0_1.trySetTitleVisiable(v2);
                this.requestOrienation(1);
                VideoEventReporter v2_1 = this.mVideoEventReporter;
                String v0_2 = this.isFromFeed ? "fullscreen_exit_back_button_list" : "fullscreen_exit_back_button_detail";
                v2_1.onEvent(v0_2);
                IVideoFullscreen videoFullscreen = this.mVideoFullscreenRef != null ? this.mVideoFullscreenRef.get() : null;
                if (videoFullscreen != null) {
                    videoFullscreen.onFullscreenChanged(this.isVideoFullscreen);
                }
                v2 = true;
            } else {
                if ((activity instanceof FeedTab)) {
                    return v2;
                }

                if (this.isFromFeed) {
                    return v2;
                }

                if (this.mRefContext == null) {
                    return v2;
                }

                if (this.mRefContext.get() == null) {
                    return v2;
                }

                this.mVideoEventReporter.onEvent("detail_video_close_key");
                this.releaseMedia();
                this.onClose();
                v2 = true;
            }
        }

        return v2;
    }

    final boolean isContextAlive() {
        return this.mRefContext != null && this.mRefContext.get() != null;
    }

    public final void onBufferingUpdate(int progress) {
        this.mMediaViewLayout.setSeekSecondaryProgress(progress);
    }

    public void clearOnCloseListener() {
        this.mCloseListenerRef = null;
    }

    public void continuePlay(boolean arg9) {
        boolean v0;
        IMediaLayout v3;
        VideoLogManager.appendLog("continuePlay");
        this.Y = false;
        this.X = false;
        this.isDirectPlay = arg9;
        this.isPauseFromList = false;
        this.mMediaViewLayout.showMediaPlayer(this.mMediaContainer);
        this.mMediaViewLayout.setIsLiveVideo(this.i);
        if (this.isPatchVideo()) {
            v3 = this.mMediaViewLayout;
            v0 = this.ao == -1 ? true : false;
            v3.setIsPatchVideo(true, v0);
        }

        if (this.mRefContext != null && ((this.mRefContext.get() instanceof FeedTab)) && (arg9) && this.C != null) {
            Object v0_1 = this.C.get();
            if (v0_1 != null) {
                this.setContainerSize(((View) v0_1).getWidth(), ((View) v0_1).getHeight());
            }
        }

        this.mMediaViewLayout.setSurfaceViewVisible(8);
        this.mMediaViewLayout.setSurfaceViewVisible(0);
        if (!this.isFromFeed || !this.isDirectPlay()) {
            this.mMediaViewLayout.setDirectPlay(false);
            this.mMediaViewLayout.dismissToolBar(true, false);
        } else {
            this.mMediaViewLayout.setDirectPlay(true);
            this.mMediaViewLayout.dismissToolBar(false, false);
        }

        if (this.o <= 0 || (this.isFromFeed) || (android.support.design.a.isTextEmpty(this.af)) || (this.isPatchVideo())) {
            this.mMediaViewLayout.setAdGoLanding(false);
        } else {
            this.mMediaViewLayout.setAdGoLanding(true);
        }

        this.mMediaViewLayout.dismissLoading();
        v3 = this.mMediaViewLayout;
        v0 = !this.al ? true : false;
        v3.setPlayerSurfaceViewSize(v0);
        this.syncPosition(true);
        if (!this.U) {
            this.schedulePendingTask(new Runnable() {

                public final void run() {
                    TTVideoController.this.a(false);
                    TTVideoController.this.d();
                }
            });
        } else {
            this.mMediaViewLayout.disableAutoRotate();
            if (this.mArticle != null) {
                this.mMediaViewLayout.showCover(this.mArticle.largeImageList, false);
            }
        }
    }

    final void d() {
        this.e();
        this.mWeakHandler.postDelayed(this.aF, 800);
    }

    public final void onVideoStatusException(int videoStatus) {
        VideoLogManager.appendLog("onVideoStatusException" + videoStatus);
        switch (videoStatus) {
            case 3:
            case 4:
            case 20:
            case 30:
            case 1000: {
                this.releaseMedia();
                break;
            }
            case 40:
            case 1002: {
                this.releaseMedia();
                break;
            }
        }
    }

    public void dismiss(boolean arg5) {
        Logger.d("TTVideoController", "dismiss");
        VideoLogManager.appendLog("dismiss");
        if ((arg5) || !this.E) {
            if (this.C != null) {
                this.C.clear();
            }

            if (!this.isPauseFromList() || !this.isPatchVideo()) {
                this.mMediaViewLayout.setVisibility(View.INVISIBLE);
            }

            int v0 = System.currentTimeMillis() - this.F < 2000 ? 1 : 0;
            if (v0 != 0) {
                return;
            }

            if (this.isVideoFullscreen) {
                return;
            }

            if ((this.isPauseFromList()) && (this.isPatchVideo())) {
                return;
            }

            this.releaseMedia(arg5);
        }
    }

    final void e() {
        this.mWeakHandler.removeCallbacks(this.aF);
    }

    private boolean e(int arg2) {
        return this.mMediaViewLayout.outOfBuffer(arg2);
    }

    public final void dismissLoading() {
        this.mWeakHandler.sendEmptyMessage(1);
        if (this.mMediaViewLayout != null) {
            this.mMediaViewLayout.dismissLoading();
        }
    }

    public final void onPrepared() {
        Logger.d("TTVideoController", "onPrepared called.");
        VideoLogManager.appendLog("onPrepared");
        this.isPrepared = true;
        if (this.mWeakHandler != null && !this.isJellyBeanMR1) {
            if (this.mLastBufferEndTime <= 0) {
                this.mLastBufferEndTime = System.currentTimeMillis();
            }

            this.mMediaViewLayout.sendDismissToolBarMsg();
            this.mWeakHandler.postDelayed(new Runnable() {
                public final void run() {
                    if (TTVideoController.this.mMediaViewLayout != null) {
                        TTVideoController.this.mMediaViewLayout.dismissLoadingCover();
                        TTVideoController.this.mMediaViewLayout.dismissLoading();
                    }
                }
            }, 1000);
        }
    }

    public Object getBindedTag() {
        return this.isVideoFullscreen ? null : this.G;
    }

    public String getCategory() {
        return this.mCategoryName;
    }

    public String getCategoryLabel(String arg3) {
        if ((this.isFromFeed) || (android.support.design.a.isTextEmpty(this.V))) {
            if ("__all__".equals(this.mCategoryName)) {
                return arg3 + "_headline";
            }
            if (android.support.design.a.isTextEmpty(this.mCategoryName)) {
                return arg3;
            }
            arg3 = arg3 + "_" + this.mCategoryName;
        } else {
            if (!"click_related".equals(this.V)
                    && !"click_album".equals(this.V) && !"click_search".equals(this.V)
                    && !"click_pgc".equals(this.V) && !"click_subject".equals(this.V) && !"click_favorite".equals(this.V)) {
                if ("__all__".equals(this.mCategoryName)) {
                    return arg3 + "_headline";
                }

                if (android.support.design.a.isTextEmpty(this.mCategoryName)) {
                    return arg3;
                }
                arg3 = arg3 + "_" + this.mCategoryName;
            } else {
                arg3 = this.V;
            }
        }

        return arg3;
    }

    public int getContainerHeight() {
        return this.mMediaViewLayout == null ? 0 : this.mMediaViewLayout.getContainerHeight();
    }

    public Context getContext() {
        if (!this.isContextAlive()) {
            return null;
        } else {
            return this.mRefContext.get();
        }
    }

    public String getCurrentLabel() {
        return null;
    }

    public long getCurrentPlayPosition() {
        return this.isVideoPlaying() || this.isVideoPaused() ? this.mCurrent : -1;
    }

    public DetailPageListener getDetailPageListener() {
        if (this.mDetailPageListenerRef != null) {
            return this.mDetailPageListenerRef.get();
        } else {
            return null;
        }
    }

    public long getGroupId() {
        return this.mArticle != null ? this.mArticle.groupId : 0;
    }

    public IMediaLayout getMediaViewLayout() {
        return this.mMediaViewLayout;
    }

    public int getPct() {
        return MediaHelper.timeToPercent(this.mCurrent, this.mDuration);
    }

    public VideoAutoPlayHelperDetail getVideoAutoPlayHelperDetail() {
        return this.mVideoAutoPlayHelperDetail;
    }

    public String getVideoId() {
        return this.mVideoId;
    }

    public final void onPrepare() {
        Logger.d("TTVideoController", "onPrepare called.");
        VideoLogManager.appendLog("onPrepare");
    }

    public void handleAdGoLandingClick(boolean arg12) {
        String v3;
        String v2;
        AbsApplication v1;
        AbsApplication application;
        String v10 = null;
        long v6 = 0;
        application = (AbsApplication) (this.mRefContext != null ? this.mRefContext.get() : v10);
        if (application == null) {
            application = BaseApplication.getApplication();
        }

        if (!android.support.design.a.isTextEmpty(this.af)) {
            if (this.o > v6) {
                if (this.isPatchVideo()) {
                    if (arg12) {
                        v1 = BaseApplication.getApplication();
                        v2 = "embeded_ad";
                        v3 = this.isFromFeed ? "feed_click_landingpage" : "detail_click_landingpage";
                        MobAdClickCombiner.onAdEvent(((Context) v1), v2, v3, this.o, v6, this.q, 0);
                    } else {
                        v1 = BaseApplication.getApplication();
                        v2 = "embeded_ad";
                        v3 = this.isFromFeed ? "feed_click" : "detail_click";
                        MobAdClickCombiner.onAdEvent(((Context) v1), v2, v3, this.o, v6, this.q, 0);
                    }

                    MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "click", this.o, v6, this.q, 0);
                } else {
                    MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "ad_click", this.o, v6, this.q, 0);
                }

                AppUtil.a(this.af, BaseApplication.getApplication());
            }
            this.ar = true;
            AdsAppActivity.openUrl((application), this.af, v10);
        }
    }

    public void handleAdJumpClick() {
    }

    public void handleBackClick(IMediaLayout mediaLayout, View view) {
        if (this.isVideoFullscreen) {
            this.isVideoFullscreen = !this.isVideoFullscreen;
            this.mMediaViewLayout.exitFullScreen(this.mMediaContainer);
            this.requestOrienation(1);
        } else {
            this.v = true;
            this.isActivityOnDestroy = true;
            this.releaseMedia();
        }
    }

    public void handleClarityChange() {
        if (this.mVideoDataContainer != null && this.mVideoDataContainer.mVideoInfo != null && this.mTTVideoEngine != null) {
            VideoItem videoItem = this.mMediaViewLayout.getSelectClarity();
            if (videoItem != null) {
                this.mDefinition = videoItem.definition;
                MediaHelper.timeToPercent(this.mCurrent, this.mDuration);
            }

            if ("360p".equals(this.mDefinition)) {
                this.mTTVideoEngine.configResolution(Resolution.Standard);
            }

            if ("480p".equals(this.mDefinition)) {
                this.mTTVideoEngine.configResolution(Resolution.High);
            }

            if ("720p".equals(this.mDefinition)) {
                this.mTTVideoEngine.configResolution(Resolution.SuperHigh);
            }
        }
    }

    public void handleCloseClick(IMediaLayout mediaLayout, View view) {
        if (!this.isFromFeed) {
            this.mVideoEventReporter.onEvent("detail_video_close_button");
        }

        this.mMediaViewLayout.releaseMediaPlayer();
        this.releaseMedia();
        this.onClose();
    }

    public void handleFullScreenBackClick(IMediaLayout mediaLayout, View view) {
        this.handleFullScreenBackClick(mediaLayout, view, false);
    }

    public void handleFullScreenBackClick(IMediaLayout mediaLayout, View view, boolean exitFullscreenByGravity) {
        if (this.isContextAlive()) {
            VideoLogManager.appendLog("handleFullScreenBackClick");
            this.isVideoFullscreen = !this.isVideoFullscreen;
            DetailPageListener detailPageListener = this.mDetailPageListenerRef != null ? this.mDetailPageListenerRef.get() : null;
            if (!this.isFromFeed && detailPageListener != null) {
                detailPageListener.onFullscreenChanged(this.isVideoFullscreen);
            }
            if (this.mRefContext.get() instanceof Activity) {
                if (this.mMediaViewLayout != null) {
                    this.mMediaViewLayout.exitFullScreen(this.mMediaContainer);
                    boolean v2 = false;
                    if ((this.isFromFeed) && (this.e)) {
                        v2 = true;
                    }
                    mMediaViewLayout.trySetTitleVisiable(v2);
                }

                this.requestOrienation(1);
                IVideoFullscreen videoFullscreen = this.mVideoFullscreenRef != null ? this.mVideoFullscreenRef.get() : null;
                if (videoFullscreen != null) {
                    ((IVideoFullscreen) videoFullscreen).onFullscreenChanged(this.isVideoFullscreen);
                }

                if (this.mArticle != null) {
                    JSONObject jsonObject = new JSONObject();
                    try {
                        jsonObject.put("item_id", this.mArticle.itemId);
                        jsonObject.put("aggr_type", this.mArticle.aggrType);
                    } catch (JSONException jsonException) {
                    }

                    if (exitFullscreenByGravity) {
                        Application application = BaseApplication.getApplication();
                        MobClickCombiner.onEvent(application,
                                "video",
                                this.isFromFeed ? "feed_fullscreen_exit_gravity_sensing" : "detail_fullscreen_exit_gravity_sensing",
                                this.mArticle.groupId,
                                this.o,
                                jsonObject);
                    } else {
                        Application application = BaseApplication.getApplication();
                        MobClickCombiner.onEvent(application,
                                "video",
                                this.isFromFeed ? "feed_fullscreen_exit_back_button" : "detail_fullscreen_exit_back_button",
                                this.mArticle.groupId,
                                this.o,
                                jsonObject);
                    }
                }

                if (this.mVideoAutoPlayHelperDetail != null) {
                    Context context = null;
                    if (this.mRefContext != null) {
                        context = this.mRefContext.get();
                    }
                    mVideoAutoPlayHelperDetail.reportFullscreenChanged(context, this.isVideoFullscreen);
                }
            } else {
                Logger.d("TTVideoController", "context is not activity, not support this function.");
                return;
            }

        }
    }

    public void handleFullScreenClick(IMediaLayout mediaLayout, View view) {
        this.handleFullScreenClick(mediaLayout, view, false, false);
    }

    public void handleFullScreenClick(IMediaLayout mediaLayout, View view, boolean arg13, boolean exitFullscreenByGravity) {
        String v0_2;
        VideoEventReporter v1;
        long v6 = 0;
        if (this.isContextAlive()) {
            this.isVideoFullscreen = !this.isVideoFullscreen;
            if (view != null && view.getId() == com.ss.android.article.browser.R.id.video_full_screen) {
                this.N = true;
            }

            if (!(this.mRefContext.get() instanceof Activity)) {
                Logger.d("TTVideoController", "context is not activity, not support this function.");
                return;
            }

            VideoLogManager.appendLog("handleFullScreenClick" + this.isVideoFullscreen);
            if (this.isVideoFullscreen) {
                this.mMediaViewLayout.enterFullScreen(this.mMediaContainer);
                this.mMediaViewLayout.trySetTitleVisiable(false);
                int v0_1 = arg13 ? 8 : 0;
                this.requestOrienation(v0_1);
                if (exitFullscreenByGravity) {
                    v1 = this.mVideoEventReporter;
                    v0_2 = this.isFromFeed ? "feed_fullscreen_gravity_sensing" : "detail_fullscreen_gravity_sensing";
                    v1.onEvent(v0_2);
                } else {
                    v1 = this.mVideoEventReporter;
                    v0_2 = this.isFromFeed ? "feed_fullscreen" : "detail_fullscreen";
                    v1.onEvent(v0_2);
                }
            } else {
                this.mMediaViewLayout.exitFullScreen(this.mMediaContainer);
                boolean titleVisible = this.isFromFeed && this.e;
                mMediaViewLayout.trySetTitleVisiable(titleVisible);
                this.requestOrienation(1);
                if (exitFullscreenByGravity) {
                    v1 = this.mVideoEventReporter;
                    v0_2 = this.isFromFeed ? "feed_fullscreen_exit_gravity_sensing" : "detail_fullscreen_exit_gravity_sensing";
                    v1.onEvent(v0_2);
                } else {
                    v1 = this.mVideoEventReporter;
                    v0_2 = this.isFromFeed ? "feed_fullscreen_exit_normal" : "detail_fullscreen_exit_normal";
                    v1.onEvent(v0_2);
                }
            }

            IVideoFullscreen videoFullscreen = this.mVideoFullscreenRef != null ? this.mVideoFullscreenRef.get() : null;
            if (videoFullscreen != null) {
                videoFullscreen.onFullscreenChanged(this.isVideoFullscreen);
            }

            if (this.isVideoFullscreen && this.o > v6) {
                String where = this.isFromFeed ? "feed_fullscreen" : "detail_fullscreen";
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", where, this.o, v6, this.q, 0);
            }
        }
    }

    public void handleFullScreenMoreClick(IMediaLayout mediaLayout, View view) {
        if (this.mShareListenerRef != null) {
            IShareListener shareListener = this.mShareListenerRef.get();
            if (shareListener != null) {
                shareListener.onFullScreenMoreClick();
            }
        }
    }

    public void handleItemShareClick(int index) {
        if (this.mPlayCompleteListenerRef != null) {
            IPlayCompleteListener playCompleteListener = this.mPlayCompleteListenerRef.get();
            if (playCompleteListener != null) {
                playCompleteListener.onItemShare(index);
            }
        }
    }

    public void handleMsg(Message message) {
        int v2 = 0;
        int v7 = com.ss.android.article.browser.R.string.video_fetch_url_fail;
        if (this.isContextAlive()) {
            Object v0 = this.mRefContext.get();
            if (this.mMediaViewLayout != null && message != null && !android.support.design.a.t(((Context) v0))) {
                switch (message.what) {
                    case 1: {
                        if (this.mTTVideoEngine != null) {
                            int v0_2 = message.obj == null || !((Boolean) message.obj).booleanValue() ? 0 : 1;
                            v2 = this.mTTVideoEngine.d();
                            int v3_1 = this.mTTVideoEngine.mDuration;
                            this.mCurrent = ((long) v2);
                            this.mDuration = ((long) v3_1);
                            if (v3_1 <= 0) {
                            } else if (v0_2 != 0 && v2 >= 500) {
                            } else {
                                this.a(((long) v2), ((long) v3_1));
                            }
                        }
                        this.mWeakHandler.sendMessageDelayed(this.mWeakHandler.obtainMessage(1), 500);
                        return;
                    }
                    case 10: {
                        v0 = this.C != null ? this.C.get() : null;
                        if (!android.support.design.a.u() || v0 != null || !this.isFromFeed || (this.isPauseFromList())) {
                            v2 = 1;
                        }

                        if (v2 == 0) {
                            return;
                        }

                        Bundle v0_1 = message.getData();
                        if (!android.support.design.a.isTextEmpty(v0_1.getString("video_id")) && this.mVideoStatistics != null) {
                            this.mVideoStatistics.c("at");
                        }

                        String v2_1 = v0_1.getString("error1");
                        String v4 = v0_1.getString("data_error1");
                        String v1_1 = v0_1.getString("url");
                        if (this.mVideoStatistics == null) {
                            return;
                        }

                        if ((TextUtils.isEmpty(((CharSequence) v2_1))) && (TextUtils.isEmpty(((CharSequence) v4)))) {
                            return;
                        }

                        this.mVideoStatistics.appendParams(v1_1, v2_1, "", v4, "");
                        return;
                    }
                    case 11: {
                        Bundle v1 = message.getData();
                        String v2_1 = v1.getString("error1");
                        String v3 = v1.getString("error2");
                        String v4 = v1.getString("data_error1");
                        String v5 = v1.getString("data_error2");
                        if (("time out".equals(v2_1)) || ("time out".equals(v3))) {
                            UIUtils.showImageToast(((Context) v0), ((Context) v0).getString(v7) + -981);
                        } else {
                            if (!"api fail".equals(v2_1) && !"api fail".equals(v3)) {
                                if (!"empty response".equals(v2_1) && !"empty response".equals(v3)) {
                                    UIUtils.showImageToast(((Context) v0), ((Context) v0).getString(v7) + -978);
                                } else {
                                    UIUtils.showImageToast(((Context) v0), ((Context) v0).getString(v7) + -979);
                                }
                            }
                            UIUtils.showImageToast(((Context) v0), ((Context) v0).getString(v7) + -980);
                        }
                        String v1_1 = v1.getString("url");
                        this.mMediaViewLayout.dismissLoading();
                        this.mMediaViewLayout.showRetry();
                        if (this.mVideoStatistics != null) {
                            this.mVideoStatistics.a();
                            this.mVideoStatistics.appendParams(v1_1, v2_1, v3, v4, v5);
                            this.mVideoStatistics.unregisterConnectivityReceiver();
                        }

                        VideoDiagnosis.a(this.mVideoId);
                        return;
                    }
                }

                return;
            }
        }
    }

    public void handleNoWifiCancelClick() {
        long v6 = 0;
        AbsApplication v1 = BaseApplication.getApplication();
        String v2 = "video";
        String v3 = "net_alert_cancel";
        long v4 = this.mArticle != null ? this.mArticle.groupId : v6;
        MobClickCombiner.onEvent(((Context) v1), v2, v3, v4, v6);
        this.releaseMedia();
    }

    public void handleNoWifiPositiveClick() {
        long v6 = 0;
        this.a(false);
        AbsApplication v1 = BaseApplication.getApplication();
        String v2 = "video";
        String v3 = "net_alert_confirm";
        long v4 = this.mArticle != null ? this.mArticle.groupId : v6;
        MobClickCombiner.onEvent(((Context) v1), v2, v3, v4, v6);
    }

    public void handleOrientationChanged(int arg3) {
        if ((this.isVideoVisible()) && !this.N && this.mTTVideoEngine != null && arg3 == 1 && (this.isVideoFullscreen)) {
            this.handleFullScreenClick(this.mMediaViewLayout, null);
        }
    }

    public void handlePatchRootViewClick() {
    }

    public void handlePlayClick(IMediaLayout arg10, View arg11) {
        long v6 = 0;
        if (this.isContextAlive()) {
            if (this.isVideoPlaying()) {
                this.pauseVideo();
                if (this.o > v6) {
                    String v3 = this.isFromFeed ? "feed_pause" : "detail_pause";
                    MobClickCombiner.onEvent(BaseApplication.getApplication(), "embeded_ad", v3, this.o, v6, this.q);
                }
            } else {
                this.k();
            }
        }
    }

    public void handleRelatedVideoClick(IMediaLayout mediaLayout, View view) {
        long v4 = 0;
        Object v0 = view.getTag();
        if (((v0 instanceof RelatedVideoItem)) && !android.support.design.a.isTextEmpty(((RelatedVideoItem) v0).mOpenUrl)) {
            MobClickCombiner.onEvent(view.getContext(), "video", "feed_click_related_video", v4, v4);
            AdsAppBaseActivity.openUrl(view.getContext(), ((RelatedVideoItem) v0).mOpenUrl, null);
            this.E = true;
            ArticleHelper.c = true;
        }
    }

    public void handleReplayClick() {
        if (this.mPlayCompleteListenerRef != null) {
            Object v0 = this.mPlayCompleteListenerRef.get();
            if (v0 != null) {
                ((IPlayCompleteListener) v0).onReplay();
            }
        }
        this.k();
    }

    public void handleRetryClick(IMediaLayout arg5, View arg6) {
        VideoLogManager.appendLog("handleRetryClick");
        if (this.mTTVideoEngine != null) {
            this.mTTVideoEngine.c();
        }

        if (this.mMediaViewLayout != null) {
            this.mMediaViewLayout.releaseMediaPlayer();
            this.mMediaViewLayout.showMediaPlayer(this.mMediaContainer);
        }

        if (this.mCurrent > 0) {
            this.O = this.mCurrent;
        }

        this.tryPlay("", this.mVideoId, this.aN);
    }

    public void handleRootViewClick(IMediaLayout arg11, View arg12, boolean arg13, boolean arg14) {
        if (!this.isFromFeed || !this.isDirectPlay()) {
            if (!this.ap) {
                if (this.isPatchVideo()) {
                    if (AppData.getInstance().isPosterAdClickEnabled()) {
                        this.handleAdGoLandingClick(false);
                        if (!this.isVideoFullscreen) {
                            return;
                        }

                        if (!this.isFromFeed) {
                            return;
                        }

                        this.releaseMedia();
                        return;
                    }

                    if (arg13) {
                        this.mMediaViewLayout.showPlayBtn(true);
                        mMediaViewLayout.setPlayIcon(!isVideoPlaying(), false);
                    } else {
                        this.mMediaViewLayout.showPlayBtn(false);
                    }

                    this.mMediaViewLayout.removeDismissToolBarMsg();
                    this.mMediaViewLayout.sendDismissToolBarMsg();
                    return;
                }

                if (arg13) {
                    if ((this.e) && this.mThirdVideoPartnerData != null && !android.support.design.a.isTextEmpty(this.mThirdVideoPartnerData.androidOpenUrl) && !android.support.design.a.isTextEmpty(this.mThirdVideoPartnerData.androidDownloadUrl) && !android.support.design.a.isTextEmpty(this.mThirdVideoPartnerData.packageName)) {
                        this.mMediaViewLayout.showToolBar(arg14, true, false);
                    } else if (this.al) {
                        mMediaViewLayout.showToolBar(arg14, false, !isPatchVideo());
                    } else {
                        this.mMediaViewLayout.showToolBar(arg14);
                    }
                }

                if (this.isVideoPlaying()) {
                    this.mMediaViewLayout.removeDismissToolBarMsg();
                    this.mMediaViewLayout.sendDismissToolBarMsg();
                } else {
                    this.mMediaViewLayout.removeDismissToolBarMsg();
                }

                if (!arg13) {
                    return;
                }

                if (this.mVideoEventReporter == null) {
                    return;
                }

                mVideoEventReporter.onEvent(isFromFeed ? "feed_click_screen" : "detail_click_screen");
            } else if (this.mSplashAdListenerRef != null) {
                ISplashAdListener splashAdListener = this.mSplashAdListenerRef.get();
                if (splashAdListener != null) {
                    if (this.mLastBufferEndTime > 0L) {
                        this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                        this.mLastBufferEndTime = 0L;
                    }
                    splashAdListener.onVideoClick(this.mTotalPlayTime, MediaHelper.timeToPercent(this.mCurrent, this.mDuration));
                }
            }
        }
    }

    public void handleShareClick() {
        if (this.mPlayCompleteListenerRef != null) {
            IPlayCompleteListener playCompleteListener = this.mPlayCompleteListenerRef.get();
            if (playCompleteListener != null) {
                playCompleteListener.onShare();
            }
        }
    }

    public void handleSplashSkipClick() {
        if (this.mSplashAdListenerRef != null) {
            ISplashAdListener splashAdListener = this.mSplashAdListenerRef.get();
            if (splashAdListener != null) {
                if (this.mLastBufferEndTime > 0L) {
                    this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                    this.mLastBufferEndTime = 0L;
                }
                splashAdListener.onSkip(this.mTotalPlayTime, MediaHelper.timeToPercent(this.mCurrent, this.mDuration));
            }
        }
    }

    public void handleThirdPartnerClick() {
        if (this.mThirdPartnerListnerRef != null) {
            IThirdPartnerListner thirdPartnerListner = this.mThirdPartnerListnerRef.get();
            if (thirdPartnerListner != null) {
                thirdPartnerListner.onClick();
            }
        }
    }

    public void handleTopMoreClick(IMediaLayout mediaLayout, View view) {
        if (this.mShareListenerRef != null) {
            IShareListener shareListener = this.mShareListenerRef.get();
            if (shareListener != null) {
                shareListener.onTopMoreClick();
            }
        }
    }

    public void handleTouchProgress(float arg9, boolean arg10) {
        long v6 = 0;
        if (this.mTTVideoEngine != null && (this.isContextAlive()) && this.mCurrent >= v6 && this.mMediaViewLayout != null) {
            Object v2 = this.mRefContext.get();
            if (this.mDuration > v6) {
                int v0 = ((int) (arg9 / (((float) this.au)) * (((float) this.at))));
                if (arg10) {
                    this.M = (((long) v0)) + this.M;
                } else {
                    this.M -= ((long) v0);
                }

                if (this.M > this.mDuration) {
                    this.M = this.mDuration;
                }

                if (this.M < v6) {
                    this.M = v6;
                }

                if (!this.mMediaViewLayout.showTouchProgress(((Context) v2), arg10, this.M, this.mDuration)) {
                    return;
                }
                this.M = this.mCurrent;
                this.mVideoEventReporter.onEvent("fullscreen_drag_process");
            }
        }
    }

    public void handleTouchUp() {
        if (this.mMediaViewLayout != null) {
            if (this.mMediaViewLayout.dismissTouchProgress()) {
                if (this.M == this.mCurrent) {
                    return;
                } else if (!this.isVideoFullscreen) {
                    return;
                } else if (this.mDuration > 0L) {
                    this.z = this.M;
                    this.e();
                    this.seekTo(this.z);
                    this.d();
                    VideoEventReporter v1 = this.mVideoEventReporter;
                    String v0 = this.isFromFeed ? "feed_move_bar" : "detail_move_bar";
                    v1.onEvent(v0);
                    if (!this.e(((int) (this.mCurrent * 100 / this.mDuration)))) {
                    } else {
                        this.mMediaViewLayout.showLoading();
                        if (this.mLastBufferEndTime > 0L) {
                            this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                            this.mLastBufferEndTime = 0L;
                        }

                        if (this.mVideoStatistics != null) {
                            this.mVideoStatistics.a(this.mVideoId, this.y);
                        }
                    }
                } else {
                    return;
                }
            }
            this.mMediaViewLayout.sendDismissToolBarMsg();
        }
    }

    public void handleTrySkipAdClick() {
        AbsApplication application = BaseApplication.getApplication();
        MobClickCombiner.onEvent(application, "embeded_ad", this.isFromFeed ? "feed_try_skip" : "detail_try_skip", this.o, 0, this.q);
    }

    public void handleVideoCoverGodetail(IMediaLayout mediaLayout, View view) {
        if (this.isContextAlive()) {
            if (this.o > 0L) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "click", this.o, 0L, this.q, 0);
            }

            if (this.mArticle == null) {
                return;
            }
            ComponentsManifest.findComponent(DetailIntentCreator.class).startNewDetailActivity(
                    BaseApplication.getApplication(),
                    this.mArticle,
                    this.o,
                    this.mCategoryName);
        }
    }

    public void handleVideoCoverReplay(IMediaLayout mediaLayout, View view) {
        long v4 = 0;
        Context v1 = view.getContext();
        String v2 = "video";
        String v3 = this.isFromFeed ? "feed_replay" : "detail_replay";
        MobClickCombiner.onEvent(v1, v2, v3, v4, v4);
        try {
            JSONObject v0_1 = new JSONObject();
            if (this.isFromFeed) {
                v0_1.put("position", "list");
            } else {
                v0_1.put("position", "detail");
            }

            if (this.mArticle == null) {
            } else {
                v0_1.put("item_id", this.mArticle.itemId);
                v0_1.put("aggr_type", this.mArticle.aggrType);
                this.a("video_play", v0_1);
            }
        } catch (JSONException jsonException) {
        }
        this.handlePlayClick(mediaLayout, view);
    }

    public void handleVolume(float arg9, boolean arg10, int arg11) {
        float v1_3;
        int v1_2;
        Object v1_1;
        float v4;
        int v7 = 3;
        float v6 = 100f;
        int v2 = 0;
        if ((this.isVideoFullscreen) && this.mTTVideoEngine != null && this.mMediaViewLayout != null) {
            Object v0 = this.mRefContext.get();
            TTVideoEngine v1 = this.mTTVideoEngine;
            if (v1.mContext == null) {
                v4 = 0f;
            } else {
                v1_1 = v1.mContext.getSystemService(Context.AUDIO_SERVICE);
                v1_2 = v1_1 != null ? ((AudioManager) v1_1).getStreamMaxVolume(v7) : 0;
                if (v1_2 < 0) {
                    v1_2 = 0;
                }

                v4 = ((float) v1_2);
            }

            if (v4 <= 0f) {
                return;
            }

            if (arg11 <= 0) {
                v1 = this.mTTVideoEngine;
                if (v1.mContext == null) {
                    v1_3 = 0f;
                } else {
                    v1_1 = v1.mContext.getSystemService(Context.AUDIO_SERVICE);
                    v1_2 = v1_1 != null ? ((AudioManager) v1_1).getStreamVolume(v7) : 0;
                    if (v1_2 >= 0) {
                        v2 = v1_2;
                    }

                    v1_3 = ((float) v2);
                }

                arg11 = ((int) ((((float) ((((int) v1_3)) * 100))) / v4));
            }

            v1_3 = arg9 / 3f;
            v1_2 = arg10 ? ((int) (v1_3 + (((float) arg11)))) : ((int) ((((float) arg11)) - v1_3));
            TTVideoEngine v2_1 = this.mTTVideoEngine;
            float v3 = (((float) v1_2)) * v4 / v6;
            v2_1.A = v3;
            v2_1.setVolume(v3, v4 * (((float) v1_2)) / v6);
            if (!this.mMediaViewLayout.showVolume(((Context) v0), v1_2)) {
                return;
            }

            this.mVideoEventReporter.onEvent("fullscreen_drag_volume");
        }
    }

    public final void onRenderStart() {
        Logger.d("TTVideoController", "onRenderStart called.");
        VideoLogManager.appendLog("onRenderStart");
        if (this.mLastBufferEndTime <= 0) {
            this.mLastBufferEndTime = System.currentTimeMillis();
        }

        this.mMediaViewLayout.dismissLoading();
        this.mMediaViewLayout.dismissLoadingCover();
    }

    public void reset(Context context, ViewGroup videoHolder, boolean isFromFeed, EnumSet arg5) {
        this.isFromFeed = isFromFeed;
        if (this.mRefContext == null || this.mRefContext.get() != context) {
            this.mRefContext = new WeakReference(context);
            this.mMediaContainer = videoHolder;
            if (this.mMediaViewLayout != null) {
                this.mMediaViewLayout.removeMediaView();
            }
            this.a(context, isFromFeed, arg5);
            this.v = false;
        }
    }

    public boolean isActivityOnDestroy() {
        return this.isActivityOnDestroy;
    }

    public boolean isAd() {
        return this.o > 0;
    }

    public boolean isCurrentVideoAutoRotatable() {
        return true;
    }

    public boolean isDirectPlay() {
        return this.isDirectPlay;
    }

    public boolean isFullScreen() {
        return this.isVideoFullscreen;
    }

    public boolean isPatchVideo() {
        return this.am == 1 || this.am == 2;
    }

    public boolean isPauseFromList() {
        return this.isPauseFromList;
    }

    public boolean isPrepared() {
        return this.isPrepared;
    }

    public boolean isVideoPaused() {
        return mTTVideoEngine != null && this.mTTVideoEngine.prevPlaybackState == 2;
    }

    public boolean isVideoPlaybackCompleted() {
        return this.mTTVideoEngine != null && this.mTTVideoEngine.prevPlaybackState == 0 && this.e;
    }

    public boolean isVideoPlaying() {
        return this.mTTVideoEngine != null && this.mTTVideoEngine.prevPlaybackState == 1;
    }

    public boolean isVideoVisible() {
        return this.mMediaViewLayout != null && this.mMediaViewLayout.getVisibility() == View.VISIBLE;
    }

    public final void onCompletion() {
        String v13;
        Object v4_3;
        JSONObject v18 = null;
        String v5;
        long v22 = 0;
        String v4;
        String v3_3;
        int v3_2;
        boolean v2_2;
        IMediaLayout v3_4;
        String v2_1;
        VideoEventReporter v3_1;
        Object v2;
        VideoLogManager.appendLog("onCompletion");
        this.mWeakHandler.removeMessages(1);
        if (TextUtils.equals(this.mVideoId, VideoPref.getLastVideoId())) {
            VideoPref.setLastVideoId(null);
            VideoPref.setLastVideoPos(-1);
        }

        DetailPageListener detailPageListener = this.mDetailPageListenerRef == null ? null : this.mDetailPageListenerRef.get();
        if (!this.isFromFeed && detailPageListener != null) {
            detailPageListener.onVideoCompletion(true);
        }

        if (this.isContextAlive()) {
            Context context = this.mRefContext.get();
            if (context instanceof IComponent) {
                if (this.mMediaViewLayout == null) {
                } else if (((IComponent) context).isDestroyed()) {
                } else {
                    if (!this.isFromFeed && !this.i && this.mVideoAutoPlayHelperDetail != null && (this.mVideoAutoPlayHelperDetail.a(this.isVideoFullscreen, this.isAd(), this.mThirdVideoPartnerData)) && (this.isVideoFullscreen)) {
                        VideoAutoPlayHelperDetail.dismissVolumeOrTouchView(this.mMediaViewLayout);
                    } else if (this.isVideoFullscreen) {
                        this.isVideoFullscreen = false;
                        if (!this.isFromFeed && detailPageListener != null) {
                            ((DetailPageListener) detailPageListener).onFullscreenChanged(this.isVideoFullscreen);
                        }

                        if (this.mMediaViewLayout != null) {
                            this.mMediaViewLayout.exitFullScreen(this.mMediaContainer);
                        }

                        this.requestOrienation(1);
                        v2 = this.mVideoFullscreenRef != null ? this.mVideoFullscreenRef.get() : null;
                        if (v2 != null) {
                            ((IVideoFullscreen) v2).onFullscreenChanged(this.isVideoFullscreen);
                        }

                        if (this.mVideoEventReporter == null) {
                        } else {
                            v3_1 = this.mVideoEventReporter;
                            v2_1 = this.isFromFeed ? "feed_fullscreen_exit_normal" : "detail_fullscreen_exit_normal";
                            v3_1.onEvent(v2_1);
                        }
                    }

                    this.mMediaViewLayout.disableAutoRotate();
                    this.mMediaViewLayout.setKeepScreenOn(false);
                    this.e();
                    this.mMediaViewLayout.setPlayIcon(true, this.i);
                    if (!this.isFromFeed || !this.isDirectPlay()) {
                        this.mMediaViewLayout.setSeekProgress(100);
                        this.mMediaViewLayout.setTimeDesc(this.aH, this.aH);
                        this.mMediaViewLayout.removeDismissToolBarMsg();
                        if (this.mThirdVideoPartnerData == null || (TextUtils.isEmpty(this.mThirdVideoPartnerData.packageName)) || (TextUtils.isEmpty(this.mThirdVideoPartnerData.androidOpenUrl)) || (TextUtils.isEmpty(this.mThirdVideoPartnerData.androidDownloadUrl))) {
                            if (this.al) {
                                v3_4 = this.mMediaViewLayout;
                                v2_2 = !this.isPatchVideo() ? true : false;
                                v3_4.showToolBar(true, false, v2_2);
                            } else {
                                this.mMediaViewLayout.showToolBar(true);
                            }
                        } else {
                            if (ToolUtils.isAppInstalled(BizApplication.getApplication(), this.mThirdVideoPartnerData.packageName)) {
                                this.mMediaViewLayout.setThirdImageUrl(this.mThirdVideoPartnerData.inBannerOpenImgUrl);
                                v3_2 = 1;
                            } else {
                                this.mMediaViewLayout.setThirdImageUrl(this.mThirdVideoPartnerData.inBannerDownloadImgUrl);
                                v3_2 = 0;
                            }

                            if (this.mThirdPartnerListnerRef != null) {
                                v2 = this.mThirdPartnerListnerRef.get();
                                if (v2 != null) {
                                    v3_3 = v3_2 != 0 ? "player_show_jump" : "player_show_download";
                                    ((IThirdPartnerListner) v2).onShowEvent(v3_3);
                                }
                            }

                            this.mMediaViewLayout.showToolBar(true, true, false);
                        }

                        this.mMediaViewLayout.dismissLoading();
                        this.mMediaViewLayout.trySetTitleVisiable(this.isFromFeed);
                    } else {
                        this.mMediaViewLayout.releaseMediaPlayer();
                    }

                    if (this.i) {
                        v3_4 = this.mMediaViewLayout;
                        v4 = ((Context) context).getResources().getString(com.ss.android.article.browser.R.string.live_video_error_end);
                        v2_2 = !this.isFromFeed ? true : false;
                        v3_4.showLiveError(v4, v2_2);
                    }

                    if (!this.isError && this.mArticle != null && this.mArticle.groupId > 0) {
                        if (this.D == null) {
                            v2 = null;
                        } else {
                            v2 = this.D.get();
                        }

                        this.mMediaViewLayout.showRelatedVideo(this.getBindedTag(), ((View) v2));
                        if (!AppData.getInstance().getAbSettings().isUseVideoFinishNewUI()) {
                        } else if (this.o > 0) {
                        } else if (this.i) {
                        } else if (this.mThirdVideoPartnerData != null) {
                        } else {
                            this.mMediaViewLayout.showNewCover(this.mArticle);
                        }
                    }

                    this.e = true;
                    long v2_4 = 0;
                    JSONObject v7 = null;
                    if (this.mVideoStatistics != null) {
                        if (this.mDuration - this.mCurrent > 2000) {
                            this.mVideoStatistics.d();
                        }

                        v7 = this.mVideoStatistics.c();
                        if (v7 == null) {
                            v22 = v2_4;
                        } else if (!v7.has("vt")) {
                            v22 = v2_4;
                        } else {
                            try {
                                v2_4 = v7.getLong("vt");
                                v22 = v2_4;
                            } catch (Exception v4_1) {
                            }
                        }
                    }
                    if (this.isError) {
                        if (!android.support.design.a.isTextEmpty((String) null)) {
                            if ((this.isPrepared) && (android.support.design.a.fixOnLineQuestion())) {
                                this.O = this.getCurrentPlayPosition();
                            }

                            ++this.as;
                            this.isError = false;
                            this.aq = false;
                            this.a(MediaHelper.getVideoSource(null));
                            this.e = true;
                            if (this.isError) {
                                this.releaseMedia(false);
                            }

                            this.mTotalPlayTime = 0;
                            return;
                        } else {
                            v5 = !NetworkUtils.isNetworkAvailable(((Context) context)) ? ((Context) context).getString(com.ss.android.article.browser.R.string.video_mobile_codec_error) + -977
                                    : ((Context) context).getString(com.ss.android.article.browser.R.string.video_mobile_codec_error) + -975;
                            if (this.mVideoDataContainer != null && !android.support.design.a.isTextEmpty(this.mVideoId) && (this.aq)) {
                                this.aq = false;
                                VideoCacheController.getInstance().setPlayFailFlag(this.mVideoId);
                            }

                            UIUtils.showImageToast((Context) context, v5);
                            if (AppData.getInstance().getAbSettings().isVideoDiagnosisEnabled()) {
                                new VideoDiagnosis(this.mVideoId, this.y, v5, null, v7).start();
                            }
                            this.releaseMedia(false);
                        }
                    }

                    if (this.mVideoEventReporter != null) {
                        if (!this.isFromFeed || (this.isFromFeed) && !this.isDirectPlay()) {
                            v3_1 = this.mVideoEventReporter;
                            v2_1 = this.isFromFeed ? "feed_over" : "detail_over";
                            v3_1.onEvent(v2_1);
                        }

                        if (!this.isFromFeed) {
                        } else if (!this.isDirectPlay()) {
                        } else if (!this.ag) {
                        } else {
                            this.mVideoEventReporter.onEvent("feed_over");
                        }
                    }

                    JSONObject v10 = new JSONObject();
                    try {
                        if (this.mLastBufferEndTime > 0) {
                            this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                            this.mLastBufferEndTime = 0;
                        }
                        if (0 > 0) {
                            this.Z = System.currentTimeMillis();
                            this.aa += this.Z;
                        }

                        v10.put("duration", this.mTotalPlayTime - this.aa);
                        if (this.e) {
                            v10.put("percent", 100);
                        } else {
                            v10.put("percent", MediaHelper.timeToPercent(this.mCurrent, this.mDuration));
                        }

                        v10.put("small_play_time", this.aa);
                        v10.put("log_extra", this.mLogExtra);
                        if (this.mArticle == null) {
                        } else if (this.mArticle.videoSubjectId <= 0) {
                        } else {
                            v10.put("video_subject_id", this.mArticle.videoSubjectId);
                        }
                    } catch (Exception v2_5) {
                    }

                    if (this.mSplashAdListenerRef != null) {
                        v2 = this.mSplashAdListenerRef.get();
                        if (v2 != null) {
                            ((ISplashAdListener) v2).onComplete(this.mTotalPlayTime, MediaHelper.timeToPercent(this.mCurrent, this.mDuration));
                        }
                    }

                    if (this.o <= 0) {
                    } else if (!this.ap) {
                        if (!this.isFromFeed || (this.isFromFeed) && !this.isDirectPlay()) {
                            if (this.isPatchVideo()) {
                                v4 = "embeded_ad";
                                v5 = this.isFromFeed ? "patch_feed_over" : "patch_detail_over";
                                MobAdClickCombiner.onAdEvent((Context) context, v4, v5, this.o, 0, v10, 0);
                            } else {
                                v4 = "embeded_ad";
                                v5 = this.isFromFeed ? "feed_over" : "detail_over";
                                MobAdClickCombiner.onAdEvent((Context) context, v4, v5, this.o, 0, v10, 0);
                            }
                        }

                        if (!this.isFromFeed) {
                        } else if (!this.isDirectPlay()) {
                        } else if (!this.ag) {
                        } else {
                            AbsApplication v3_5 = BaseApplication.getApplication();
                            v4 = "embeded_ad";
                            v5 = this.isPatchVideo() ? "patch_feed_over" : "feed_over";
                            MobAdClickCombiner.onAdEvent(((Context) v3_5), v4, v5, this.o, 0, v10, 0);
                        }
                    } else {
                        JSONObject v3_6 = null;
                        try {
                            v18 = new JSONObject();
                            v18.put("log_extra", this.mLogExtra);
                            v18.put("duration", this.mTotalPlayTime);
                            v18.put("percent", MediaHelper.timeToPercent(this.mTotalPlayTime, this.mDuration));
                        } catch (JSONException v2_6) {
                            v2_6.printStackTrace();
                        }
                        MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "splash_ad", "play_over", this.o, 0, v18, 3);
                    }
                    try {
                        v3_3 = "position";
                        v2_1 = this.isFromFeed ? "list" : "detail";
                        v10.put(v3_3, v2_1);
                        this.a(v10);
                    } catch (JSONException v2_6) {
                    }

                    if (this.mArticle != null) {
                        try {
                            v10.put("item_id", this.mArticle.itemId);
                            v10.put("aggr_type", this.mArticle.aggrType);
                        } catch (JSONException v2_6) {
                        }

                        if (!this.isFromFeed || (this.isFromFeed) && !this.isDirectPlay()) {
                            if (!this.o()) {
                                this.a((Context) context, "video_over", v10);
                            } else if (!this.isFromFeed && this.mVideoAutoPlayHelperDetail != null) {
                                VideoAutoPlayHelperDetail v3_7 = this.mVideoAutoPlayHelperDetail;
                                if (this.mRefContext == null) {
                                    v4_3 = null;
                                } else {
                                    v4_3 = this.mRefContext.get();
                                }

                                v3_7.onEvent(((Context) v4_3), this.getCategoryLabel("click"), this.mArticle.groupId, this.o, v10);
                            }
                        }

                        if (!this.isDirectPlay) {

                        } else {
                            v18 = new JSONObject();
                            try {
                                v18.put("duration", this.mTotalPlayTime);
                                v18.put("percent", MediaHelper.timeToPercent(this.mCurrent, this.mDuration));
                                v18.put("log_extra", this.mLogExtra);
                                v3_3 = "position";
                                v2_1 = this.isFromFeed ? "list" : "detail";
                                v18.put(v3_3, v2_1);
                                v18.put("item_id", this.mArticle.itemId);
                                if (this.mArticle.videoSubjectId > 0) {
                                    v18.put("video_subject_id", this.mArticle.videoSubjectId);
                                }
                                this.a(v18);
                            } catch (Exception v2_5) {
                            }

                            if (this.isFromFeed) {
                                v2_1 = this.ag ? "feed_back_play_over" : "feed_play_over";
                                v13 = v2_1;
                            } else {
                                v13 = "auto_detail_play_over";
                            }

                            if (this.o > 0) {
                                MobAdClickCombiner.onAdEvent((Context) context, "embeded_ad", v13, this.o, 0, v18, 0);
                            } else {
                                MobClickCombiner.onEvent((Context) context, "video_over", v13, this.mArticle.groupId, 0, v18);
                            }

                            if (!this.isFromFeed) {
                            } else if (!this.ag) {
                            } else {
                                this.a((Context) context, "video_over", v10);
                            }
                        }
                    }

                    label_689:
                    if ((this.isDirectPlay()) && (this.isFromFeed)) {
                        this.releaseMedia();
                        this.mTotalPlayTime = 0;
                        this.aa = 0;
                    }

                    if (this.mDetailPageListenerRef != null) {
                        this.mDetailPageListenerRef.get();
                    }

                    if (this.am == 1) {
                        this.mTotalPlayTime = 0;
                        this.aa = 0;
                        if (this.mVideoStatistics != null) {
                            this.mVideoStatistics.registerConnectivityReceiver(this.mVideoId);
                            this.mVideoStatistics.appendAdLeave(v22);
                        }
                        if (this.mArticle == null) {
                        } else {
                            this.aq = shouldPreloadVideo(this.mArticle);
                        }
                    } else if (this.am == 3) {
                        this.e();
                        this.isPauseFromList = false;
                    } else if (this.am == 2) {
                        if (this.mTTVideoEngine != null) {
                            this.mTTVideoEngine.c();
                        }
                        this.e();
                        this.mTotalPlayTime = 0;
                        this.mLastBufferEndTime = 0;
                        this.mCurrent = 0;
                        this.mDuration = 0;
                        this.e = false;
                        this.isPrepared = false;
                        this.isError = false;
                        this.z = 0;
                        this.O = -1;
                        this.mVideoHeight = 0;
                        this.mVideoWidth = 0;
                        this.am = -1;
                        this.al = false;
                        this.aG = 0;
                        this.an = 0;
                        this.ao = 0;
                        this.o = 0;
                        this.isPauseFromList = false;
                        this.doUnregisterReceiver();
                        this.s();
                    } else {
                        this.mTotalPlayTime = 0;
                        this.aa = 0;
                        if (this.mVideoAutoPlayHelperDetail != null && !this.isFromFeed && !this.i && (android.support.design.a.hasVideo(this.mArticle)) && this.mThirdVideoPartnerData == null) {
                            if ((this.isAd()) && !this.isPatchVideo()) {
                            } else {
                                this.mVideoAutoPlayHelperDetail.a(this, (Context) context, this.isVideoFullscreen);
                            }
                        }
                    }
                }
            }
        }
        this.e = true;
        if (this.isError) {
            this.releaseMedia(false);
        }
        this.mTotalPlayTime = 0;
    }

    private void k() {
        String v3;
        String v2;
        AbsApplication v1_3;
        JSONObject v0_2 = null;
        long v6 = 0;
        this.mMediaViewLayout.sendDismissToolBarMsg();
        this.mWeakHandler.removeMessages(1);
        if (this.isVideoPlaybackCompleted()) {
            VideoEventReporter v1 = this.mVideoEventReporter;
            String v0 = this.isFromFeed ? "feed_play" : "detail_play";
            v1.onEvent(v0);
        }

        this.a(false);
        this.mMediaViewLayout.sendDismissToolBarMsg();
        this.e();
        this.d();
        try {
            v0_2 = new JSONObject();
            if (this.isFromFeed) {
                v0_2.put("position", "list");
            } else {
                v0_2.put("position", "detail");
            }
        } catch (JSONException jsonException) {
        }

        this.a("video_play", v0_2);
        if (this.o > v6) {
            if (this.isVideoPlaybackCompleted()) {
                v1_3 = BaseApplication.getApplication();
                v2 = "embeded_ad";
                v3 = this.isFromFeed ? "feed_play" : "detail_play";
                MobAdClickCombiner.onAdEvent(((Context) v1_3), v2, v3, this.o, v6, this.q, 0);
            } else {
                v1_3 = BaseApplication.getApplication();
                v2 = "embeded_ad";
                v3 = this.isFromFeed ? "feed_continue" : "detail_continue";
                MobClickCombiner.onEvent(((Context) v1_3), v2, v3, this.o, v6, this.q);
            }
        }
    }

    private void l() {
        boolean isJellyBeanMR1 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
        this.isJellyBeanMR1 = isJellyBeanMR1;
        this.mVideoEventReporter = new VideoEventReporter(BizApplication.getApplication());
    }

    private void doRegisterReceiver() {
        if (!this.isReceiverRegistered) {
            AbsApplication application = BaseApplication.getApplication();
            this.isReceiverRegistered = true;
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
            try {
                application.registerReceiver(this.mBroadcastReceiver, intentFilter);
            } catch (Exception exception) {
            }
        }
    }

    private void doUnregisterReceiver() {
        if (this.isReceiverRegistered) {
            AbsApplication application = BaseApplication.getApplication();
            this.isReceiverRegistered = false;
            try {
                application.unregisterReceiver(this.mBroadcastReceiver);
            } catch (Exception e) {
            }
        }
    }

    private boolean o() {
        return !this.isFromFeed && this.mVideoAutoPlayHelperDetail != null && (this.mVideoAutoPlayHelperDetail.b);
    }

    public void onActivityDestroy() {
    }

    public void onEnterDetailEvent() {
        this.ag = true;
        AbsApplication application = BaseApplication.getApplication();
        JSONObject jsonObject = new JSONObject();
        try {
            if (this.mLastBufferEndTime > 0L) {
                this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                this.mLastBufferEndTime = 0;
            }

            jsonObject.put("duration", this.mTotalPlayTime);
            jsonObject.put("percent", MediaHelper.timeToPercent(this.mCurrent, this.mDuration));
            jsonObject.put("log_extra", this.mLogExtra);
            jsonObject.put("position", this.isFromFeed ? "list" : "detail");
            if (this.mArticle != null) {
                jsonObject.put("item_id", this.mArticle.itemId);
            }
        } catch (JSONException jsonException) {
        }

        if (this.o > 0L) {
            MobAdClickCombiner.onAdEvent(application, "embeded_ad", "click_feed_auto_play", this.o, 0L, jsonObject, 0);
        } else {
            long groupId = this.mArticle != null ? this.mArticle.groupId : 0L;
            MobClickCombiner.onEvent(application, "enter_detail", "click_feed_auto_play", groupId, 0L, jsonObject);
        }
    }

    public void onProgressChanged(IMediaLayout arg7, SeekBar arg8, int arg9, boolean arg10) {
        long v4 = 0;
        if (this.isContextAlive()) {
            Object v0 = this.mRefContext.get();
            this.z = this.mDuration > v4 ? ((long) (((int) ((((float) ((((long) arg9)) * this.mDuration))) / (((float) ((Context) v0).getResources().getInteger(com.ss.android.article.browser.R.integer.video_progress_max))))))) : v4;
        }
    }

    public void onStartTrackingTouch(IMediaLayout mediaLayout, SeekBar seekBar) {
        this.e();
        this.ae = this.z;
        this.mMediaViewLayout.removeDismissToolBarMsg();
    }

    public void onStopTrackingTouch(IMediaLayout arg13, SeekBar arg14) {
        long v10 = 0;
        this.mWeakHandler.removeMessages(1);
        this.seekTo(this.z);
        this.mMediaViewLayout.sendDismissToolBarMsg();
        VideoEventReporter v1 = this.mVideoEventReporter;
        String v0 = this.isFromFeed ? "feed_move_bar" : "detail_move_bar";
        v1.onEvent(v0);
        JSONObject v8 = new JSONObject();
        try {
            if (this.mLastBufferEndTime > v10) {
                this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                this.mLastBufferEndTime = System.currentTimeMillis();
            }

            if (this.z - this.ae > v10) {
                v8.put("drag_pct", MediaHelper.timeToPercent(this.z - this.ae, this.mDuration));
                v8.put("drag_time", this.z - this.ae);
            } else {
                v8.put("drag_pct", MediaHelper.timeToPercent(this.ae - this.z, this.mDuration) * -1);
                v8.put("drag_time", -1 * this.ae - this.z);
            }

            String v1_1 = "log_extra";
            v0 = TextUtils.isEmpty(this.mLogExtra) ? "" : this.mLogExtra;
            v8.put(v1_1, v0);
            v1_1 = "position";
            v0 = this.isFromFeed ? "list" : "detail";
            v8.put(v1_1, v0);
            if (this.mArticle == null) {
            } else {
                v8.put("item_id", this.mArticle.itemId);
            }
        } catch (JSONException v0_1) {
        }
        AbsApplication v1_2 = BaseApplication.getApplication();
        String v2 = "drag_bar";
        String v3 = "video_bar";
        long v4 = this.mArticle != null ? this.mArticle.groupId : v10;
        MobClickCombiner.onEvent(((Context) v1_2), v2, v3, v4, this.o, v8);
        if (this.e(arg14.getProgress())) {
            this.mMediaViewLayout.showLoading();
            if (this.mLastBufferEndTime > v10) {
                this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                this.mLastBufferEndTime = System.currentTimeMillis();
            }
        }
    }

    private void p() {
        this.av = System.currentTimeMillis() + "_" + AppLog.deviceId();
    }

    public void pauseAtList() {
        Logger.d("TTVideoController", "pauseAtList");
        VideoLogManager.appendLog("pauseAtList");
        if (this.mMediaViewLayout != null) {
            this.isPauseFromList = true;
            if (this.mTTVideoEngine != null) {
                this.mTTVideoEngine.pause();
            }

            this.mMediaViewLayout.dismissNoWifiNoticeDialog();
            this.mMediaViewLayout.setKeepScreenOn(false);
            this.mMediaViewLayout.releaseMediaPlayer();
            this.e();
            if (this.C != null) {
                this.C.clear();
            }

            if (this.D != null) {
                Object v0 = this.D.get();
                if (v0 != null && ((v0 instanceof RelativeLayout))) {
                    ((RelativeLayout) v0).removeAllViews();
                    ((View) v0).setVisibility(View.GONE);
                }

                this.D.clear();
            }

            this.doUnregisterReceiver();
            this.s();
        }
    }

    public void pauseVideo() {
        long v10 = 0;
        Logger.d("TTVideoController", "pauseVideo");
        VideoLogManager.appendLog("pauseVideo");
        if (this.mLastBufferEndTime > v10) {
            this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
            this.mLastBufferEndTime = v10;
        }

        if (this.mTTVideoEngine != null) {
            this.mTTVideoEngine.pause();
        }

        this.abandonAudioFocus();
        this.mMediaViewLayout.removeDismissToolBarMsg();
        this.mMediaViewLayout.setKeepScreenOn(false);
        if (!this.al) {
            IMediaLayout v3 = this.mMediaViewLayout;
            boolean v0 = (this.isPatchVideo()) || !this.al ? false : true;
            v3.showToolBar(true, false, v0);
            this.mMediaViewLayout.setPlayIcon(true, this.i);
        } else {
            if (!this.isPatchVideo()) {
                return;
            }

            if (AppData.getInstance().isPosterAdClickEnabled()) {
                return;
            }

            this.mMediaViewLayout.setPlayIcon(true, this.i);
        }
    }

    public boolean play(CellRef cellRef, int arg15, int arg16, View arg17, View arg18, boolean arg19) {
        if (this.getContext() != null && (android.support.design.a.isTest(this.getContext()))) {
            Toast.makeText(this.getContext(), "ttvideoplayer", Toast.LENGTH_SHORT).show();
        }

        VideoLogManager.appendLog("playList");
        VideoCacheManager.getInstance().cancelPreDownload();
        boolean v2;
        if (!this.isContextAlive() || this.mMediaViewLayout == null) {
            v2 = false;
        } else if (cellRef == null) {
            this.releaseMedia(false);
            v2 = false;
        } else {
            Article article = cellRef.article;
            if (article != null && !android.support.design.a.isTextEmpty(article.videoId)) {
                if (!android.support.design.a.isTextEmpty(this.mVideoId) && !this.mVideoId.equals(article.videoId)) {
                    this.releaseMedia(true);
                }

                if (!AppData.getInstance().hasVideoKeepPos() || !TextUtils.equals(article.videoId, VideoPref.getLastVideoId())) {
                    this.O = -1;
                } else {
                    this.O = VideoPref.getLastVideoPos();
                    MobClickCombiner.onEvent(BaseApplication.getApplication(), "list_over", "list_continue");
                }
                this.mMediaViewLayout.resetClaritySelectors();
                this.p();
                this.isPauseFromList = false;
                this.U = false;
                this.V = null;
                this.isActivityOnDestroy = false;
                this.o = cellRef.getAdId();
                this.logPb = cellRef.logPb;
                this.isDirectPlay = arg19;
                this.mLogExtra = cellRef.logExtra;
                this.q = new JSONObject();
                try {
                    if (android.support.design.a.isTextEmpty(this.mLogExtra)) {
                    } else {
                        this.q.put("log_extra", this.mLogExtra);
                    }
                } catch (JSONException v2_1) {
                }
                this.mWeakHandler = new WeakHandler(((Callback) this));
                this.mTotalPlayTime = 0;
                this.isError = false;
                this.setBindedTag(article);
                this.C = new WeakReference(arg17);
                this.D = new WeakReference(arg18);
                this.mCategoryName = cellRef.category;
                this.mArticle = article;
                this.i = article.videoType == 1;
                this.isFromFeed = true;
                this.as = 0;
                this.mMediaViewLayout.setOuterVideoCellType(cellRef.videoStyle);
                if (cellRef.videoStyle == 7 || cellRef.videoStyle == 8 || cellRef.videoStyle == 12) {
                    this.mMediaViewLayout.setTitleTextSize(16);
                } else if (cellRef.videoStyle == 9) {
                    this.mMediaViewLayout.setTitleTextSize(15);
                }

                if (this.isAd()) {
                    this.mMediaViewLayout.showOrHideWatermark(false);
                } else {
                    this.mMediaViewLayout.showOrHideWatermark(true);
                }

                this.mMediaViewLayout.showMediaPlayer(this.mMediaContainer);
                this.mMediaViewLayout.setTitle(article.title);
                this.mMediaViewLayout.setBtnAdInfo(article.aF, this.mRefContext);
                AppData.getInstance();
                mMediaViewLayout.setTheme(AppData.isNightMode());
                long v2_3 = this.O > 0 ? this.O : 0;
                this.a(v2_3, ((long) (article.videoDuration * 1000)));
                this.mDuration = -1;
                this.aq = shouldPreloadVideo(article);
                if (this.i) {
                    this.mVideoWidth = arg17.getWidth();
                    this.mVideoHeight = arg17.getHeight();
                }

                if (this.mArticle != null) {
                    this.mVideoEventReporter.setData("video", this.mArticle, this.o, this.mArticle.videoSubjectId);
                }

                String v2_4;
                if (!this.isFromFeed || (this.isFromFeed) && !arg19) {
                    VideoEventReporter v3 = this.mVideoEventReporter;
                    v2_4 = this.isFromFeed ? "feed_play" : "detail_play";
                    v3.onEvent(v2_4);
                }

                if (this.o > 0) {
                    if ((this.isFromFeed) && !arg19) {
                        MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "feed_play", this.o, 0, this.q, 2);
                    }
                    AppUtil.a(article.adVideoClickTrackUrls, BaseApplication.getApplication());
                }

                this.setContainerSize(arg17.getWidth(), arg17.getHeight());
                this.syncPosition(false);
                this.mVideoStatistics = new VideoStatistics(BaseApplication.getApplication(), article.videoId);
                this.mVideoStatistics.setWid(this.av);
                SystemClock.elapsedRealtime();
                this.tryPlay("", article.videoId, article.sp());
                v2_4 = this.isFromFeed ? "list" : "detail";
                if (this.mArticle != null) {
                    JSONObject v10 = new JSONObject();
                    try {
                        v10.put("position", v2_4);
                        v10.put("item_id", this.mArticle.itemId);
                        v10.put("aggr_type", this.mArticle.aggrType);
                        v10.put("log_extra", this.mLogExtra);
                    } catch (JSONException v2_1) {
                    }

                    if (!arg19) {
                        this.a("video_play", v10);
                    } else if (this.o > 0) {
                        MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "feed_auto_play", this.o, 0, v10, 2);
                    } else {
                        MobClickCombiner.onEvent(BaseApplication.getApplication(), "video_play", "feed_auto_play", this.mArticle.groupId, 0, v10);
                    }
                }

                this.doRegisterReceiver();
                this.v = false;
                return true;
            }

            this.releaseMedia(false);
            v2 = false;
        }

        return v2;
    }

    public boolean play(String url,
                        String categoryName,
                        String title,
                        long adId,
                        Article article,
                        String videoId,
                        int sp,
                        int videoWidth,
                        int videoHeight,
                        List trackUrlList,
                        long lastPos,
                        String arg34,
                        boolean isDirectPlay,
                        String externalUrl,
                        String logextra,
                        JSONObject arg38) {
        return this.play(url, categoryName, title, adId, article, videoId, sp, videoWidth, videoHeight, trackUrlList, lastPos, arg34, isDirectPlay, externalUrl, false, logextra, arg38);
    }

    public boolean play(String arg13, String arg14, String title, long arg16, Article article, String arg19, int arg20, int arg21, int arg22, List trackUrlList, long arg24, String arg26, boolean isDirectPlay, String arg28, boolean arg29, String arg30, JSONObject arg31) {
        Context context;
        boolean v2;
        if (this.getContext() != null && (android.support.design.a.isTest(this.getContext()))) {
            Toast.makeText(this.getContext(), "ttvideoplayer", Toast.LENGTH_SHORT).show();
        }

        VideoLogManager.appendLog("playDetail");
        VideoCacheManager.getInstance().cancelPreDownload();
        if (!this.isContextAlive()) {
            v2 = false;
            return v2;
        }

        if ((android.support.design.a.isTextEmpty(arg19)) && (android.support.design.a.isTextEmpty(arg13))) {
            Logger.e("TTVideoController", "No video info");
            return false;
        }

        if (!android.support.design.a.isTextEmpty(this.mVideoId) && !this.mVideoId.equals(arg19) && (this.isVideoVisible())) {
            this.releaseMedia(true);
        }

        this.mMediaViewLayout.resetClaritySelectors();
        int v2_1 = 0;
        if (!AppData.getInstance().hasVideoKeepPos() || !TextUtils.equals(arg19, VideoPref.getLastVideoId())) {
            this.O = arg24;
        } else {
            long v4 = VideoPref.getLastVideoPos();
            if (v4 > 0 && arg24 <= 0) {
                this.O = v4;
                v2_1 = 1;
                MobClickCombiner.onEvent(BaseApplication.getApplication(), "list_over", "detail_continue");
            } else {
                this.O = arg24;
            }
        }

        int v3 = v2_1 != 0 || arg24 > 0 ? v2_1 : 1;
        this.p();
        this.isPauseFromList = false;
        this.U = false;
        this.isActivityOnDestroy = false;
        this.isDirectPlay = isDirectPlay;
        if (arg31 != null) {
            this.logPb = arg31.optJSONObject("log_pb");
            this.searchResultId = arg31.optLong("search_result_id");
            this.source = arg31.optString("source");
            this.query = arg31.optString("query");
        }

        this.mArticle = article;
        this.i = article.isLiveVideo();
        this.isError = false;
        this.mCategoryName = arg14;
        this.mMediaViewLayout.setVideoSize(arg21, arg22);
        this.mMediaViewLayout.showMediaPlayer(this.mMediaContainer);
        this.mMediaViewLayout.dismissNewCover();
        this.mMediaViewLayout.dismissAllEndCover();
        this.isFromFeed = false;
        this.mDuration = -1;
        this.aq = shouldPreloadVideo(article);
        this.mMediaViewLayout.setTitle(title);
        this.V = arg26;
        this.as = 0;
        if (arg29) {
            this.setContainerSize(arg21, arg22);
        } else {
            this.setContainerSize(-1, arg22);
        }

        if (this.mVideoAutoPlayHelperDetail != null) {
            this.mVideoAutoPlayHelperDetail.a(this.mMediaViewLayout, this.isFromFeed, this.mMediaContainer);
            if (!this.mVideoAutoPlayHelperDetail.a) {
                Context context1 = this.isContextAlive() ? this.mRefContext.get() : null;
                v2_1 = context1 instanceof Activity ? ((Activity) context1).getRequestedOrientation() : 1;
                if (v2_1 == 1) {
                    this.requestOrienation(0);
                }
            }
        }

        if (v3 != 0 && !this.e) {
            this.af = arg28;
            this.mLogExtra = arg30;
            this.o = arg16;
            this.al = arg29;
            this.q = new JSONObject();
            try {
                if (!android.support.design.a.isTextEmpty(this.mLogExtra)) {
                    this.q.put("log_extra", this.mLogExtra);
                } else {
                }
            } catch (JSONException v2_3) {
            }

            if (this.mArticle != null) {
                this.mVideoEventReporter.setData("video", this.mArticle, this.o, this.mArticle.videoSubjectId);
            }

            VideoEventReporter v3_1 = this.mVideoEventReporter;
            String v2_4 = this.isFromFeed ? "feed_play" : "detail_play";
            v3_1.onEvent(v2_4);
            if (this.o > 0) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "detail_play", this.o, 0, this.q, 0);
                AppUtil.a(trackUrlList, BaseApplication.getApplication());
            }

            this.mVideoStatistics = new VideoStatistics(BaseApplication.getApplication(), arg19);
            this.mVideoStatistics.setWid(this.av);
            SystemClock.elapsedRealtime();
            v2_4 = this.isFromFeed ? "list" : "detail";
            JSONObject v10 = new JSONObject();
            if (this.mArticle != null) {
                try {
                    v10.put("position", v2_4);
                    v10.put("item_id", this.mArticle.itemId);
                    v10.put("aggr_type", this.mArticle.aggrType);
                } catch (JSONException v2_3) {
                }
            }

            if (!this.o()) {
                this.a("video_play", v10);
            } else if (!this.isFromFeed) {
                try {
                    v10.put("version_type", "high");
                } catch (JSONException v2_3) {
                }

                if (this.mRefContext == null) {
                    context = null;
                } else {
                    context = (Context) this.mRefContext.get();
                }
                VideoAutoPlayHelperDetail.onEvent(context, "video_play_auto", this.getCategoryLabel("click"), this.mArticle.groupId, this.o, v10);
            }

            this.mTotalPlayTime = 0;
            this.tryPlay(arg13, arg19, arg20);
            if (this.isAd()) {
                this.mMediaViewLayout.showOrHideWatermark(false);
            } else {
                this.mMediaViewLayout.showOrHideWatermark(true);
            }
            this.doRegisterReceiver();
            this.v = false;
            return true;
        }
        this.mMediaViewLayout.setVideoSize(this.mVideoWidth, this.mVideoHeight);
        v2 = !this.e || (this.isDirectPlay) ? false : true;
        this.U = v2;
        if ((this.isDirectPlay) && this.mArticle != null) {
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("position", "detail");
                jsonObject.put("item_id", this.mArticle.itemId);
                jsonObject.put("aggr_type", this.mArticle.aggrType);
            } catch (JSONException jsonException) {
            }
            this.a("video_play", jsonObject);
            if (this.o > 0) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "detail_play", this.o, 0, this.q, 0);
            }
        }

        this.continuePlay(this.isDirectPlay);
        this.doRegisterReceiver();
        if (this.isAd()) {
            this.mMediaViewLayout.showOrHideWatermark(false);
        } else {
            this.mMediaViewLayout.showOrHideWatermark(true);
        }

        return true;
    }

    public boolean playSplashUrl(String localUrl,
                                 String videoId,
                                 String arg14,
                                 String arg15,
                                 long arg16,
                                 int arg18,
                                 int arg19,
                                 List trackUrlList,
                                 String arg21,
                                 String arg22,
                                 int arg23,
                                 boolean arg24,
                                 boolean arg25) {
        Logger.d("TTVideoController", "video local url " + localUrl);
        Logger.d("TTVideoController", "video mVideoId " + videoId);
        if (!this.isContextAlive()) {
            return false;
        }

        if (!android.support.design.a.isTextEmpty(videoId) && !android.support.design.a.isTextEmpty(localUrl)) {
            if (!android.support.design.a.isTextEmpty(this.mVideoId) && !this.mVideoId.equals(videoId) && (this.isVideoVisible())) {
                this.releaseMedia(true);
            }
            this.p();
            this.isPauseFromList = false;
            this.U = false;
            this.isActivityOnDestroy = false;
            this.af = arg21;
            this.o = arg16;
            this.isError = false;
            this.mCategoryName = arg14;
            this.mMediaViewLayout.setIsSplashAdVideo(true, arg24, arg25);
            this.mMediaViewLayout.setVideoSize(arg18, arg19);
            this.mMediaViewLayout.showMediaPlayer(this.mMediaContainer);
            if (!(this.mMediaViewLayout.getLayoutParams() instanceof FrameLayout.LayoutParams)) {
                Logger.d("TTVideoController", "syncPositionForSplash layout params!");
            } else {
                this.mMediaContainer.getLocationInWindow(this.h);
                FrameLayout.LayoutParams v2_1 = this.mMediaViewLayout.getLayoutParams();
                if (v2_1 != null) {
                    v2_1.topMargin = arg23;
                    v2_1.leftMargin = 0;
                    v2_1.gravity = 51;
                    this.mMediaViewLayout.setLayoutParams(v2_1);
                }
            }

            this.isFromFeed = false;
            this.mDuration = -1;
            this.mMediaViewLayout.setTitle(arg15);
            this.mWeakHandler = new WeakHandler(((Callback) this));
            this.al = true;
            this.setContainerSize(arg18, arg19);
            this.ap = true;
            this.mTotalPlayTime = 0;
            this.mMediaViewLayout.dismissToolBar(false, true);
            this.mMediaViewLayout.trySetTitleVisiable(false);
            this.mMediaViewLayout.showLoading();
            try {
                this.aq = false;
                this.a(localUrl);
            } catch (Exception v2_2) {
            }

            this.mLogExtra = arg22;
            this.q = new JSONObject();
            try {
                if (android.support.design.a.isTextEmpty(this.mLogExtra)) {
                } else {
                    this.q.put("log_extra", this.mLogExtra);
                }
            } catch (JSONException jsonException) {
            }

            if (this.mArticle != null) {
                this.mVideoEventReporter.setData("video", this.mArticle, this.o, this.mArticle.videoSubjectId);
            }

            this.v = false;
            return true;
        } else {
            Logger.e("TTVideoController", "No video info");
            return false;
        }
    }

    private void onClose() {
        ICloseListener closeListener = this.mCloseListenerRef != null ? this.mCloseListenerRef.get() : null;
        if (closeListener != null) {
            closeListener.onClose(false);
        } else {
            Logger.e("TTVideoController", "close listenerRef is null or empty");
        }
    }

    private void executePendingTaskOnSurfaceOnCreated() {
        if (!this.isPendingTaskRunning && this.mPendingTaskOnSurfaceCreatedList != null && !this.mPendingTaskOnSurfaceCreatedList.isEmpty()) {
            this.isPendingTaskRunning = true;
            Iterator<Runnable> iterator = new ArrayList(this.mPendingTaskOnSurfaceCreatedList).iterator();
            while (iterator.hasNext()) {
                iterator.next().run();
            }
            this.mPendingTaskOnSurfaceCreatedList.clear();
            this.isPendingTaskRunning = false;
        }
    }

    public void registerReshowEndCoverCallback() {
        this.mReshowEndCoverCallback = new ReshowEndCoverCallback(this);
        if (this.mReshowEndCoverCallback != null) {
            CallbackCenter.addCallback(IVideoController.RESHOW_END_COVER, this.mReshowEndCoverCallback);
        }
    }

    public void registerStopEndCoverCallback() {
        this.mStopAutoPlayAnimationCallback = new StopAutoPlayAnimationCallback(this);
        if (this.mStopAutoPlayAnimationCallback != null) {
            CallbackCenter.addCallback(IVideoController.STOP_END_COVER, this.mStopAutoPlayAnimationCallback);
        }
    }

    public void releaseMedia() {
        this.isPauseFromList = false;
        this.U = false;
        this.releaseMedia(false);
    }

    public void releaseMediaFromSplash(boolean arg11, int breakReason) {
        JSONObject jsonObject = null;
        if (arg11) {
            try {
                jsonObject = new JSONObject();
                if (this.mLastBufferEndTime > 0L) {
                    this.mTotalPlayTime += System.currentTimeMillis() - this.mLastBufferEndTime;
                    this.mLastBufferEndTime = 0;
                }
                jsonObject.put("break_reason", breakReason);
                jsonObject.put("duration", this.mTotalPlayTime);
                jsonObject.put("percent", MediaHelper.timeToPercent(this.mTotalPlayTime, this.mDuration));
                jsonObject.put("log_extra", this.mLogExtra);
            } catch (JSONException jsonException) {
                jsonException.printStackTrace();
            }
            MobAdClickCombiner.onAdEvent(BizApplication.getApplication(), "splash_ad", "play_break", this.o, 0L, jsonObject, 0);
        }

        Logger.d("TTVideoController", "mDuration :" + this.mDuration);
        Logger.d("TTVideoController", "mCurrent :" + this.mCurrent);
        Logger.d("TTVideoController", "mTotalPlayTime :" + this.mTotalPlayTime);
        this.releaseMedia();
    }

    public void releaseWhenOnPause() {
        AppData.getInstance().getAbSettings().isEnableFeedBackWithVideoLog();
        if (!this.isPauseFromList) {
            if (this.ar) {
                this.ar = false;
                this.pauseAtList();
            } else {
                this.releaseMedia();
            }
        }
    }

    public void releaseWithMiniVideo(boolean arg2) {
        if (arg2) {
            this.releaseMedia(true);
        }
    }

    public void requestOrienation(int arg6) {
        int v4 = 1024;
        if (this.isContextAlive()) {
            int v1 = arg6 == 0 || arg6 == 8 ? 1 : 0;
            if (v1 == 0) {
                this.N = false;
            }

            Context context = this.mRefContext.get();
            if (context instanceof Activity) {
                Activity activity = (Activity) context;
                try {
                    activity.setRequestedOrientation(arg6);
                } catch (Throwable throwable) {
                }

                if (this.mMediaViewLayout != null) {
                    this.mMediaViewLayout.dismissVolume();
                    this.mMediaViewLayout.dismissTouchProgress();
                }

                if (v1 != 0) {
                    activity.getWindow().setFlags(v4, v4);
                } else {
                    this.F = System.currentTimeMillis();
                    activity.getWindow().clearFlags(v4);
                }
            }
        }
    }

    public void resumeMedia(View coverImageIv, View arg5) {
        Logger.d("TTVideoController", "resumeMedia");
        VideoLogManager.appendLog("resumeMedia");
        if (this.C == null || this.C.get() == null) {
            this.C = new WeakReference(coverImageIv);
            this.D = new WeakReference(arg5);
        }

        if (!this.E) {
            this.C = new WeakReference(coverImageIv);
            this.D = new WeakReference(arg5);
            this.mMediaViewLayout.setVisibility(View.VISIBLE);
        }
        this.E = false;
    }

    public void resumeVideo() {
        VideoLogManager.appendLog("resumeVideo");
        this.schedulePendingTask(new Runnable() {
            @Override
            public final void run() {
                if (!TTVideoController.this.isVideoPlaying() && TTVideoController.this.mMediaViewLayout != null) {
                    NetworkType v0 = null;
                    if (TTVideoController.this.isContextAlive()) {
                        v0 = NetworkUtils.getNetworkType((Context) TTVideoController.this.mRefContext.get());
                    }
                    if (TTVideoController.this.mMediaViewLayout != null && (TTVideoController.this.mMediaViewLayout.isNoWifiDialogShowing()) && v0 != null && !AppData.getInstance().userAllowUseMobileNet && v0 != NetworkType.WIFI && v0 != NetworkType.NONE) {
                        return;
                    }
                    Logger.d("TTVideoController", "resumeVideo");
                    TTVideoController.this.mMediaViewLayout.setVisibility(View.VISIBLE);
                    TTVideoController.this.mMediaViewLayout.sendDismissToolBarMsg();
                    TTVideoController.this.e();
                    TTVideoController.this.d();
                    TTVideoController.this.a(false);
                }
            }
        });
    }

    private void s() {
        if (this.mPendingTaskOnSurfaceCreatedList != null && !this.mPendingTaskOnSurfaceCreatedList.isEmpty()) {
            this.mPendingTaskOnSurfaceCreatedList.clear();
        }
    }

    public void setActivityOnDestroy(boolean arg1) {
        this.isActivityOnDestroy = arg1;
    }

    public void setBindedTag(Object arg1) {
        this.G = arg1;
    }

    public void setDetailPageListener(DetailPageListener arg2) {
        this.mDetailPageListenerRef = new WeakReference(arg2);
        if (this.mVideoAutoPlayHelperDetail != null) {
            this.mVideoAutoPlayHelperDetail.setDetailPageListener(arg2);
        }
    }

    public void setFullScreenListener(IVideoFullscreen arg2) {
        this.mVideoFullscreenRef = new WeakReference(arg2);
    }

    public void setOnCloseListener(ICloseListener arg2) {
        this.mCloseListenerRef = new WeakReference(arg2);
    }

    public void setPlayCompleteListener(IPlayCompleteListener playCompleteListener) {
        this.mPlayCompleteListenerRef = new WeakReference(playCompleteListener);
    }

    public void setShareListener(IShareListener shareListener) {
        this.mShareListenerRef = new WeakReference(shareListener);
    }

    public void setSplashAdListener(ISplashAdListener splashAdListener) {
        this.mSplashAdListenerRef = new WeakReference(splashAdListener);
    }

    public void showAdGoLanding(String arg5) {
        this.af = arg5;
        if (this.o > 0 && !this.isFromFeed && !android.support.design.a.isTextEmpty(this.af) && !this.isPatchVideo()) {
            this.mMediaViewLayout.setAdGoLanding(true);
        }
    }

    public boolean showBackwardVideo(Article article, long arg3, String arg5, int arg6, int arg7, String arg8, String arg9, long arg10, String arg12) {
        return true;
    }

    public void showNewCover(Article article) {
        if (this.mMediaViewLayout != null) {
            this.mMediaViewLayout.showNewCover(article);
        }
    }

    public void showThirdPartnerGuide(ThirdVideoPartnerData thirdVideoPartnerData, IThirdPartnerListner thirdPartnerListner) {
        this.mThirdVideoPartnerData = thirdVideoPartnerData;
        this.mThirdPartnerListnerRef = new WeakReference(thirdPartnerListner);
    }

    public void stopAutoPlayAnimation() {
        if (this.mMediaViewLayout != null) {
            this.mMediaViewLayout.stopAutoPlayEndCover();
        }
    }

    public void surfaceChanged(IMediaLayout mediaLayout, SurfaceHolder surfaceHolder, int format, int width, int height) {
        Logger.d("TTVideoController", "surfaceChanged, format = " + format + ", width = " + width + ", height = " + height);
    }

    public void surfaceCreated(IMediaLayout mediaLayout, SurfaceHolder surfaceHolder) {
        Logger.d("TTVideoController", "surfaceCreated");
        VideoLogManager.appendLog("surfaceCreated");
        if (!this.Y) {
            this.X = true;
            if (this.mTTVideoEngine != null && (this.isContextAlive())) {
                mTTVideoEngine.mSurfaceHolder = surfaceHolder;
                if (mTTVideoEngine.mMediaPlayerClient != null) {
                    mTTVideoEngine.mMediaPlayerClient.setDisplay(surfaceHolder);
                }

                this.Y = true;
                this.mRefContext.get();
                if (this.U) {
                    this.pauseVideo();
                    return;
                }

                this.executePendingTaskOnSurfaceOnCreated();
            }
        }
    }

    public void surfaceDestroyed(IMediaLayout arg3, SurfaceHolder arg4) {
        this.X = false;
        this.Y = false;
        Logger.d("TTVideoController", "surfaceDestroyed");
        VideoLogManager.appendLog("surfaceDestoryed");
    }

    public void syncPosition(boolean arg5) {
        if (!this.isVideoFullscreen) {
            Object v0 = this.C != null ? this.C.get() : null;
            if (v0 == null) {
                return;
            }

            if (!this.isFromFeed) {
                return;
            }

            ((View) v0).getLocationInWindow(this.g);
            if (!(this.mMediaViewLayout.getLayoutParams() instanceof FrameLayout.LayoutParams)) {
                return;
            }

            this.mMediaContainer.getLocationInWindow(this.h);
            if (arg5) {
                this.mWeakHandler.post(this.az);
                return;
            }

            FrameLayout.LayoutParams v0_1 = this.mMediaViewLayout.getLayoutParams();
            if (v0_1 == null) {
                return;
            }

            v0_1.topMargin = this.g[1] - this.h[1];
            v0_1.leftMargin = this.g[0];
            v0_1.gravity = 51;
            this.mMediaViewLayout.setLayoutParams(v0_1);
        }
    }

    private void abandonAudioFocus() {
        try {
            if (this.mOnAudioFocusChangeListener != null) {
                AudioManager am = (AudioManager) AbsApplication.getApplication().getSystemService(Context.AUDIO_SERVICE);
                am.abandonAudioFocus(this.mOnAudioFocusChangeListener);
                this.mOnAudioFocusChangeListener = null;
            }
        } catch (Throwable throwable) {
        }
    }

    public void textureViewCreated(IMediaLayout mediaLayout, Surface surface) {
        Logger.d("TTVideoController", "textureViewCreated");
        VideoLogManager.appendLog("textureViewCreated");
        if (this.mTTVideoEngine != null) {
            TTVideoEngine v0 = this.mTTVideoEngine;
            v0.mSurface = surface;
            if (v0.mMediaPlayerClient != null) {
                v0.mMediaPlayerClient.setSurface(surface);
            }
            this.Y = true;
            if (this.U) {
                this.pauseVideo();
                return;
            }
            this.executePendingTaskOnSurfaceOnCreated();
        }
    }

    public void unRegisterReceiver() {
        this.doUnregisterReceiver();
    }

    public void unregisterReshowEndCoverCallback() {
        if (this.mReshowEndCoverCallback != null) {
            CallbackCenter.removeCallback(IVideoController.RESHOW_END_COVER, this.mReshowEndCoverCallback);
        }
    }

    public void unregisterStopEndCoverCallback() {
        if (this.mStopAutoPlayAnimationCallback != null) {
            CallbackCenter.removeCallback(IVideoController.STOP_END_COVER, this.mStopAutoPlayAnimationCallback);
        }
    }
}

